Opening windows from the renderer
- JavaScript calling
window.open()
For same-origin content, the new window is created within the same process, enabling the parent to access the child window directly. This can be very useful for app sub-windows that act as preference panels, or similar, as the parent can render to the sub-window directly, as if it were a div
in the parent. This is the same behavior as in the browser.
When nativeWindowOpen
is set to false, window.open
instead results in the creation of a BrowserWindowProxy, a light wrapper around BrowserWindow
.
BrowserWindow constructor options are set by, in increasing precedence order: parsed options from the features
string from window.open()
, security-related webPreferences inherited from the parent, and options given by . Note that webContents.setWindowOpenHandler
has final say and full privilege because it is invoked in the main process.
url
StringframeName
String (optional)
Returns BrowserWindowProxy |
A subset of WebPreferences
can be set directly, unnested, from the features string: zoomFactor
, nodeIntegration
, preload
, javascript
, contextIsolation
, and webviewTag
.
For example:
- Node integration will always be disabled in the opened if it is disabled on the parent window.
- Context isolation will always be enabled in the opened
window
if it is enabled on the parent window. - JavaScript will always be disabled in the opened
window
if it is disabled on the parent window. frameName
follows the specification ofwindowName
located in the native documentation.
To customize or cancel the creation of the window, you can optionally set an override handler with webContents.setWindowOpenHandler()
from the main process. Returning { action: 'deny' }
cancels the window. Returning { action: 'allow', overrideBrowserWindowOptions: { ... } }
will allow opening the window and setting the BrowserWindowConstructorOptions
to be used when creating the window. Note that this is more powerful than passing options through the feature string, as the renderer has more limited privileges in deciding security preferences than the main process.