// main.js
const mainWindow = new BrowserWindow()
// In this example, only windows with the `about:blank` url will be created.
// All other urls will be blocked.
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
if (url === 'about:blank') {
return {
action: 'allow',
overrideBrowserWindowOptions: {
frame: false,
fullscreenable: false,
backgroundColor: 'black',
webPreferences: {
preload: 'my-child-window-preload-script.js',
nativeWindowOpen: true
}
}
}
}
return { action: 'deny' }
})
本机窗口示例
没有此选项时出错
1条答案
按热度按时间9rbhqvlz1#
当nativeWindowOpen设置为true时,默认行为被启用,并且Electron将创建一个新的浏览器窗口来显示链接的内容当遇到target="_blank”时不呈现相同的窗口。