MozillaZine

Opening a new browser window (development)

From MozillaZine Knowledge Base

(Difference between revisions)
Revision as of 20:53, 1 December 2004
Ted Mielczarek (Talk | contribs)

<-- Previous diff
Revision as of 03:17, 19 December 2004
Asqueella (Talk | contribs)

Next diff -->
Line 1: Line 1:
 +{{extdev}}
 +
=Opening a new browser window= =Opening a new browser window=
To open a new browser window, you can simply use window.open. However, window.open returns a DOMWindow, not a ChromeWindow, 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. To open a new browser window, you can simply use window.open. However, window.open returns a DOMWindow, not a ChromeWindow, 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>+<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() ;+var b = newWindow.getBrowser();</pre>
-</pre>+ 
 +[[Category:Development]]

Revision as of 03:17, 19 December 2004

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

Opening a new browser window

To open a new browser window, you can simply use window.open. However, window.open returns a DOMWindow, not a ChromeWindow, so you can't get access to the browser chrome from it. You can, however use nsIWindowMediator to get the window you just opened.

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