user1256960
user1256960

Reputation: 303

Window id in xul

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?

Upvotes: 0

Views: 323

Answers (1)

Wladimir Palant
Wladimir Palant

Reputation: 57651

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));

Upvotes: 1

Related Questions