Search code examples
greasemonkeymeta-tagsuserscripts

Adding <meta> redirect using Greasemonkey


I'm looking to add <meta> element to specific websites using Greasemonkey script. The idea is to redirect the website to another page after X minutes. Something like below:

<META HTTP-EQUIV="Refresh" CONTENT="60; URL=http://example.com">

What is the simplest way to get this done?


Solution

  • You can use Greasemonkey (or JavaScript) to add the meta node, but it won't be parsed (at least in FF 4.0). AFAIK, browsers are only expected to parse meta directives on initial load.

    You can use JavaScript to "redirect" the page, after an interval, like so:

    setTimeout (function() {
        window.location.href    = "http://example.com";
        },
        60000 //-- 60 seconds
    );
    

    If you don't want the original page to remain in the browser's history, use:

    setTimeout (function() {
        window.location.replace ("http://example.com");
        },
        60000 //-- 60 seconds
    );