NsIWindowMediator: Difference between revisions
From MozillaZine Knowledge Base
Jump to navigationJump to search
No edit summary |
m (categories) |
||
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
- Getting the most recent / any window of given type.
- 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| }