[Project_owners] Global listeer
Nickolay Ponomarev
asqueella at gmail.com
Thu Nov 15 07:17:44 PST 2007
On Nov 15, 2007 12:31 PM, Michael Vincent van Rantwijk, MultiZilla
<mv_van_rantwijk at yahoo.com> wrote:
> Nickolay Ponomarev wrote:
> > On Nov 15, 2007 11:06 AM, Michael Vincent van Rantwijk, MultiZilla
> > <mv_van_rantwijk at yahoo.com> wrote:
> >>> //register Observer
> >>> window.addEventListener("load", MyObserver, false);
> >>> function MyObserver(){
> >>> var observerService = Components.classes["@mozilla.org/observer-service;1"]
> >>> .getService(Components.interfaces.nsIObserverService);
> >> Don't do that here, but outside the observer; because it will 'run' for
> >> all loads!
> >>
> > Huh?
>
> This is two fold as moving "var observerService" out of the observer
> scope, makes the observer a few ms faster, and there is probably no need
> to add a new observer for each time the load event is triggered.
>
The listener added via window.addEventListener('load' ...) will not
run more than once, no? It handles the chrome window's load.
I saw some people checking that the listener doesn't do anything when
called a second time, but never got a reasonable explanation why that
was necessary. (It may have been necessary many years ago, but
extensions for modern versions of Firefox work fine relying on the
'load' listener firing only once.)
Nickolay
More information about the Project_owners
mailing list