Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I redirect some page with javascript in Greasemonkey? [duplicate]

Hey, I want to redirect a page when it finish loading...

For example, when google.com finish loading, I want to send a javascript to search something...

How can I do it ?

like image 800
Bruno 'Shady' Avatar asked Jul 02 '10 20:07

Bruno 'Shady'


2 Answers

This is simply how I would go about redirecting:

//==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 the Google and Yahoo! URLs with something else. You don't need any external libraries (jQuery) or something complicated like that.

I would not reccomend this as it is more of a nuisance than a help to the end user, however that depends on what the function of the script is.

like image 61
esqew Avatar answered Sep 23 '22 04:09

esqew


Use window.location.replace(url) if you want to redirect the user in a way that the current page is forgotten by the back button, because otherwise if you use window.location = url then when the user presses the back button, then the userscript will kick in again and push them back the page that they were just on.

like image 42
erikvold Avatar answered Sep 21 '22 04:09

erikvold