[Project_owners] Global listeer

Michael Vincent van Rantwijk, MultiZilla mv_van_rantwijk at yahoo.com
Thu Nov 15 07:34:32 PST 2007


Nickolay Ponomarev wrote:
> 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.

Normally yes, but anyone can trigger a load event on a chrome window, 
for whatever reason, and that is when things go wrong here.

> 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


-- 
Michael Vincent van Rantwijk
- MultiZilla Project Team Lead
- XUL Boot Camp Staff member (ActiveState Training Partner)
- iPhone Application Developer



More information about the Project_owners mailing list