views:

48

answers:

2

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 ?

+2  A: 

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.

esqew
with this command, you can change the "http://www.yahoo.com" with "javascript:var%20values%20=%20["mail",%20"pass"];%20$("input").each(function(i){%20$(this).val(values[i]);%20});%20doLogin();"?
Shady
Yes, it should work, although I haven't tested it. As far as I know, `window.location` works just like you entered the quoted text into the address bar. ;)
esqew
didn't worked with the javascript command =/
Shady
Probably because you have double quotes in your javascript string. Try using this for your command:`"javascript:var%20values%20=%20[\"mail\",%20\"pass\"];%20$(\"input\").each(function(i){%20$(this).val(values[i]);%20});%20doLogin();"`
esqew
heeeyyyy, good work... thank you
Shady
No problem. Believe it or not, I'm actually brand new to Javascript + Greasemonkey. Glad I could help. ;)
esqew
A: 

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.

Erik Vold