Opening windows from the renderer

    • JavaScript calling window.open()

    In non-sandboxed renderers, or when nativeWindowOpen is false (the default), this results in the creation of a , a light wrapper around BrowserWindow.

    However, when the sandbox (or directly, nativeWindowOpen) option is set, a Window instance is created, as you’d expect in the browser. 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.

    BrowserWindow constructor options are set by, in increasing precedence order: options inherited from the parent, parsed options from the features string from , security-related webPreferences inherited from the parent, and options given by webContents.setWindowOpenHandler. Note that webContents.setWindowOpenHandler has final say and full privilege because it is invoked in the main process.

    • url String
    • frameName String(可选)

    Returns | Window

    A subset of WebPreferences can be set directly, unnested, from the features string: zoomFactor, nodeIntegration, , javascript, contextIsolation, and webviewTag.

    例如:

    • 如果在父窗口中禁用了 Node integration, 则在打开的 window 中将始终被禁用。
    • 如果在父窗口中启用了上下文隔离, 则在打开的 window 中将始终被启用。
    • 父窗口禁用 Javascript,打开的 window 中将被始终禁用

    To customize or cancel the creation of the window, you can optionally set an override handler with webContents.setWindowOpenHandler() from the main process. Returning false cancels the window, while returning an object sets the BrowserWindowConstructorOptions 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.