[Greasemonkey] Getting script to run once the page fully loads

Edward Kawas edward.kawas at gmail.com
Fri May 19 14:57:28 EDT 2006


Hi Mark,

 when I did window.addEventListener('load', my_entire_script_code, false), my
code actually was called before the page loaded. In fact, I changed the 'load'
to unload, blur, etc and my code was called regardless.

When I removed the line
 window.addEventListener('load', my_entire_script_code, false);

The code didn't run, so I am fairly confident that that listener was calling my
code.

Eddie

> -----Original Message-----
> From: greasemonkey-bounces at mozdev.org 
> [mailto:greasemonkey-bounces at mozdev.org] On Behalf Of Mark Pilgrim
> Sent: Friday, May 19, 2006 1:45 PM
> To: greasemonkey at mozdev.org
> Subject: Re: [Greasemonkey] Getting script to run once the 
> page fully loads
> 
> On 5/19/06, Jeremy Dunck <jdunck at gmail.com> wrote:
> > Actually, user scripts inject just before the load event-- on the 
> > firefox-specific DOMContentLoaded event.
> >
> > chrome/browser.js:
> > GM_BrowserUI.chromeLoad = function(e) { ...
> >   GM_listen(this.appContent, "DOMContentLoaded", GM_hitch(this, 
> > "contentLoad")); ...
> > }
> >
> > GM_BrowserUI.contentLoad = function(e) { ...
> >   if (GM_getEnabled() && GM_isGreasemonkeyable(href)) { ..
> >     this.gmSvc.domContentLoaded({ wrappedJSObject: unsafeWin }); ...
> > }
> >
> > components/greasemonkey.js:
> >   domContentLoaded: function(wrappedWindow) { ...
> >       this.injectScripts(scripts, href, unsafeWin);
> 
> This is all very interesting, but does not answer the 
> original poster's question.  If I understand it correctly, 
> you want a Greasemonkey script to load *after* the page is 
> completely finished loading, including all external images, etc.
> 
> If so, then what you need to do is define an onload handler 
> and call your main function from it, like so:
> 
> function my_entire_script_code() {
> ... my code...
> }
> 
> window.addEventListener('load', my_entire_script_code, false);
> 
> Hope this helps.
> 
> --
> Cheers,
> -Mark
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey



More information about the Greasemonkey mailing list