从渲染进程打开窗口
- 在 JavaScript 中调用
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(可选)
Returns BrowserWindowProxy |
A subset of WebPreferences
can be set directly, unnested, from the features string: zoomFactor
, nodeIntegration
, preload
, javascript
, contextIsolation
, and webviewTag
.
例如:
- 如果在父窗口中禁用了 Node integration, 则在打开的 中将始终被禁用。
- 如果在父窗口中启用了上下文隔离, 则在打开的
window
中将始终被启用。 - 父窗口禁用 Javascript,打开的
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.