Window id in xul

Go To StackoverFlow.com

0

I have a question regarding window id in xul. I have something like in my xul file and I want to access this window from javascript. Basically, I want a function to return me a reference to that window using the name of it. Is there any function to do that?

2012-04-04 08:03
by user1256960


1

If you have a top-level XUL window, you can get a reference to it using nsIWindowMediator, like this:

Components.utils.import("resource://gre/modules/Services.jsm");

Services.wm.getMostRecentWindow("navigator:browser");

navigator:browser is the type of the browser window, you would have to use the windowtype attribute value of your window. Note that this isn't using the id attribute - the ID is a different thing and mostly useful to apply overlays.

To get more than one window of the same type you would write:

var enumerator = Services.wm.getEnumerator("navigator:browser");
while (enumerator.hasMoreElements())
  alert(enumerator.getNext().QueryInterface(Components.interfaces.nsIDOMWindow));
2012-04-04 08:25
by Wladimir Palant
Ads