docs: fix webContents 'new-window' event handler sample (#18067)
This commit is contained in:
parent
b333ce2628
commit
d2cebc62d1
1 changed files with 8 additions and 3 deletions
|
@ -138,11 +138,16 @@ new [`BrowserWindow`](browser-window.md). If you call `event.preventDefault()` a
|
|||
instance, failing to do so may result in unexpected behavior. For example:
|
||||
|
||||
```javascript
|
||||
myBrowserWindow.webContents.on('new-window', (event, url) => {
|
||||
myBrowserWindow.webContents.on('new-window', (event, url, frameName, disposition, options) => {
|
||||
event.preventDefault()
|
||||
const win = new BrowserWindow({ show: false })
|
||||
const win = new BrowserWindow({
|
||||
webContents: options.webContents, // use existing webContents if provided
|
||||
show: false
|
||||
})
|
||||
win.once('ready-to-show', () => win.show())
|
||||
win.loadURL(url)
|
||||
if (!options.webContents) {
|
||||
win.loadURL(url) // existing webContents will be navigated automatically
|
||||
}
|
||||
event.newGuest = win
|
||||
})
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue