Opening windows from the renderer
- clicking on links or submitting forms adorned with
target=_blank
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.
Electron pairs this native Chrome Window
with a BrowserWindow under the hood. You can take advantage of all the customization available when creating a BrowserWindow in the main process by using webContents.setWindowOpenHandler()
for renderer-created windows.
url
stringframeName
string (optional)features
string (optional)
Returns | null
features
is a comma-separated key-value list, following the standard format of the browser. Electron will parse out of this list where possible, for convenience. For full control and better ergonomics, consider using webContents.setWindowOpenHandler
to customize the BrowserWindow creation.
For example:
Notes:
- 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. - Non-standard features (that are not handled by Chromium or Electron) given in
features
will be passed to any registeredwebContents
‘sdid-create-window
event handler in the argument. - When opening
about:blank
, the child window’sWebPreferences
will be copied from the parent window, and there is no way to override it because Chromium skips browser side navigation in this case.
In addition to passing in action
and overrideBrowserWindowOptions
, outlivesOpener
can be passed like: { action: 'allow', outlivesOpener: true, overrideBrowserWindowOptions: { ... } }
. If set to true
, the newly created window will not close when the opener window closes. The default value is false
.