How can I redirect some pages using javascript in Greasemonkey?

Hey, I want to redirect the page when it finishes loading ...

For example, when google.com finishes loading, I want to send javascript to search for something ...

How can i do this?

+7
javascript firefox greasemonkey
source share
3 answers

This is just how I will redirect:

//==UserScript== // @name Redirect Google // @namespace whatever.whatever... // @description Redirect Google to Yahoo! // @include http://www.google.com // @include http://www.google.com/* // @include http://*.google.com/* //==/UserScript== window.location = "http://www.yahoo.com" 

... of course, replacing Google and Yahoo! URLs with something else. You don't need external libraries (jQuery) or anything like that.

I would not recommend this, as this is more of a nuisance than helping the end user, however it depends on what the script function is.

+7
source share

Use window.location.replace(url) if you want to redirect the user so that the current page is forgotten by the back button, because otherwise, if you use window.location = url , then when the user clicks the back button ", and again release the page they were just on.

+4
source share

This method is the most flexible that I have found so far. It is easy to specify multiple redirects in one script:

 // ==UserScript== // @name Redirector // @namespace http://use.iEyour.homepage/ // @version 0.1 // @description enter something useful // @match http://*/* // @copyright 2012+, You // @run-at document-start // ==/UserScript== //Any page on youtube.com is automatically redirected to google.com - you can use this //function to redirect from any page to any other page. redirectToPage("http://www.youtube.com/", "http://www.google.com"); //You can put several of these redirects in a single script! redirectToPage("en.wikipedia.org", "http://www.stackoverflow.com"); function redirectToPage(page1, page2){ if(window.location.href.indexOf(page1) != -1){ window.location.href = page2; } } 
+4
source share

All Articles