MozillaZine

Opening a new browser window (development)

From MozillaZine Knowledge Base

(Difference between revisions)
Revision as of 00:25, 6 March 2005
Asqueella (Talk | contribs)

<-- Previous diff
Revision as of 11:48, 9 August 2005
Asqueella (Talk | contribs)

Next diff -->
Line 1: Line 1:
{{extdev}} {{extdev}}
-==Opening a new browser window==+To open a new browser window, you can simply use <code>window.open</code>. However, <code>window.open</code> returns a <code>Window</code> object for content, not for the browser window itself, so you should get the chrome <code>Window</code> first. The simplest way to do that is to use [[nsIWindowMediator]].
-To open a new browser window, you can simply use <code>window.open</code>. However, <code>window.open</code> returns a <code>DOMWindow</code>, not a <code>ChromeWindow</code>, so you can't get access to the browser chrome from it. You can, however use [http://xulplanet.com/references/xpcomref/ifaces/nsIWindowMediator.html nsIWindowMediator] to get the window you just opened.+
-===Example===+== Example ==
-<pre>window.open();+ window.open();
-var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]+ var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
- .getService(Components.interfaces.nsIWindowMediator);+ .getService(Components.interfaces.nsIWindowMediator);
-var newWindow = wm.getMostRecentWindow("navigator:browser");+ var newWindow = wm.getMostRecentWindow("navigator:browser");
-var b = newWindow.getBrowser();</pre>+ var b = newWindow.getBrowser();
 + 
 +== Other resources ==
 +* More [[:Category:Example code|example code]].
 +* Working with [[nsIWindowMediator]].
 +* More about [http://developer.mozilla.org/en/docs/Working_with_windows_in_chrome_code working with windows].
[[Category:Example code|Opening a new browser window]] [[Category:Example code|Opening a new browser window]]

Revision as of 11:48, 9 August 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).

To open a new browser window, you can simply use window.open. However, window.open returns a Window object for content, not for the browser window itself, so you should get the chrome Window first. The simplest way to do that is to use nsIWindowMediator.

Example

window.open();
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
                   .getService(Components.interfaces.nsIWindowMediator);
var newWindow = wm.getMostRecentWindow("navigator:browser");
var b = newWindow.getBrowser();

Other resources