>
> Quote: "Greasemonkey only runs scripts when the page has loaded anyway"
>
> This isn't really, completely true. Or not true at all. (afaik)
>
> I think the person wants an "after onload" execution, which truly executes
> after the page has completely loaded.
>
> Check out one of my extensions here:
>
> http://www.snowcrest.net/donnelly/firefox/gmscripts/colorfix.user.js
>
> Specifically, the "unsafeWindow.addEventListener ("load", ...." part.
> Although I'm not sure if using "unsafeWindow.addEventListener" is the
> correct or best way to do it now.
>
> And you can get to the page's functions and variables. I would do it using
> the "unsafeWindow." thing, but there may be a better way to do it without
> using "unsafeWindow", whose use is discouraged as much as possible for
> security reasons.
>
> Did I get close or closer?
>
Very Close.
This is exactly what I want to do. But I cannot get the following code working!
Please help
function tester(){
window.location.href="http://www.google.com";
unsafeWindow.addEventListener ("load", function () { tester2() }, false);
}
The function tester2 never gets called
First: Don't use unsafeWindow here. "window.addEventListener" is
equivalent, and it is not unsafe.
> The function tester2 never gets called
Of course not. The immediately previous line changes the location to a
new document. So this page stops loading, and scripts in it stop running.
Changing the location always stops currently running scripts. You need
a new script to run at the new location.
You should read what Anthony wrote and actually think about what is happening when your code runs. If you load a different page to the one you are currently on, then the script will stop running and everything starts over from a blank page.
What you are trying to do is slightly absurd and goes something like this:
Load new page
script starts running
Script adds event listener
Event listener gets called
Firefox executes the line that changes page
Rest of the script is ignored as a new page loads
Repeat above sequence of events
In other words, the "do something at page xxx/yyy" never gets to execute because you change the page (wipe the event listener) before firefox even gets to it.
On 7 Jan 2011 16:25, "steveb" <pchr...@gmail.com> wrote:
On 5 Jan., 15:00, Anthony Lieuallen <arant...@gmail.com> wrote:
> On 01/05/11 01:19, arif wrote:
>
...
I have the same problem with my script.
My script looks like the following snippet:
window.addEventListener("load", funX(){
window.location.href = "http://www.xxx.x";
// do something on www.xxx.x
},false);
// do something
window.addEventListener("load", funY(){
window.location.href = "http://www.yyy.y";
// do something on www.yyy.y
}, false);
what can i do to fix my code?
--
You received this message because you are subscribed to the Google Groups "greasemonk...