MozillaZine

NsIWindowMediator

From MozillaZine Knowledge Base

(Difference between revisions)
Revision as of 00:13, 28 April 2005
Asqueella (Talk | contribs)

<-- Previous diff
Revision as of 00:14, 28 April 2005
Asqueella (Talk | contribs)
(categories)
Next diff -->
Line 31: Line 31:
== References == == References ==
* [http://xulplanet.com/references/xpcomref/ifaces/nsIWindowMediator.html nsIWindowMediator reference page on XUL Planet] * [http://xulplanet.com/references/xpcomref/ifaces/nsIWindowMediator.html nsIWindowMediator reference page on XUL Planet]
 +
 +[[Category:Example code]] [[Category:XPCOM example code]]

Revision as of 00:14, 28 April 2005

This page is part of the extension development documentation project.

Ask your questions in MozillaZine Forums. Also try browsing example code.

Note: development documentation is in process of being moved to Mozilla Development Center (MDC).

Window mediator is Mozilla component that keeps track of open windows. It's accessed through nsIWindowMediator interface. Two most common uses of nsIWindowMediator are

  1. Getting the most recent / any window of given type.
  2. Enumerating all windows of given type.

In the examples below type specifies the type of windows you want to search. You can specify a type of your own window by creating an windowtype attribute on the <window> element.

Browser windows have navigator:browser window type. To search all windows, regardless of their type, pass an empty string, "".

Getting most recent window

var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
         getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow(type);

Enumerating windows

var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
         getService(Components.interfaces.nsIWindowMediator);
var enumerator = wm.getEnumerator(type);
while(enumerator.hasMoreElements()) {
  var win = enumerator.getNext();
  // do something with |win|
}


References