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?

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
user1256960
  • 303
  • 3
  • 11

1 Answers1

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));
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126