Opening a new browser window (development): Difference between revisions

From MozillaZine Knowledge Base
Jump to navigationJump to search
No edit summary
m (update link)
Line 1: Line 1:
{{extdev}}
{{extdev}}


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>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 [http://developer.mozilla.org/en/docs/nsIWindowMediator nsIWindowMediator].


== Example ==
== Example ==

Revision as of 21:02, 19 September 2006

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