mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
docs: update the example of webContents.setWindowOpenHandler to cla… (#50293)
docs: reorganize the comments for clarifying `webContents.setWindowOpenHandler` example Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: z0gSh1u <zx.cs@qq.com>
This commit is contained in:
@@ -1485,6 +1485,11 @@ mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
const browserView = new BrowserView(options)
|
||||
mainWindow.addBrowserView(browserView)
|
||||
browserView.setBounds({ x: 0, y: 0, width: 640, height: 480 })
|
||||
// For `background-tab` disposition (e.g., when middle-clicking or ctrl/cmd-clicking a link),
|
||||
// `options.webContents` is undefined because its creation can be deferred. So load the URL manually.
|
||||
if (details.disposition === 'background-tab') {
|
||||
browserView.webContents.loadURL(details.url)
|
||||
}
|
||||
return browserView.webContents
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user