[Project_owners] Global listeer

Nickolay Ponomarev asqueella at gmail.com
Thu Nov 15 01:10:43 PST 2007


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?

> >    1. how can i find that observer is registered before or not ?
>
> Have you looked at enumerateObservers in nsIObserverService.idl already?
>
Oops. Still you shouldn't use it, at least in your case. (I question
the kosherness of its in-tree uses).

> >    2. when i register observer only when first window opens every thing
> >    is ok, when i open some other windows still every thing is ok and observer
> >    works perfectly, but when i close first window while other windows are still
> >    open the observer doesn't work anymore ?!
>
> There is a hidden window which you can use, or better use a (JavaScript)
> component to store your global vars and observers, which makes listening
> for opening and closing of (browser) windows also a lot easier.
>
Can we stop suggesting people use the hidden window? It's an
implementation detail really, not to be used by extensions.

Nickolay


More information about the Project_owners mailing list