[ci skip] Improve docs for new-window
event
This should help clarify the purpose of `event.newGuest` as per the recent discussion in #7407.
This commit is contained in:
parent
e8f689ecd3
commit
197ad915b7
1 changed files with 14 additions and 3 deletions
|
@ -157,9 +157,20 @@ requested by `window.open` or an external link like `<a target='_blank'>`.
|
||||||
|
|
||||||
By default a new `BrowserWindow` will be created for the `url`.
|
By default a new `BrowserWindow` will be created for the `url`.
|
||||||
|
|
||||||
Calling `event.preventDefault()` will prevent creating new windows. In such case, the
|
Calling `event.preventDefault()` will prevent Electron from automatically creating a
|
||||||
`event.newGuest` may be set with a reference to a `BrowserWindow` instance to make it
|
new `BrowserWindow`. If you call `event.preventDefault()` and manually create a new
|
||||||
used by the Electron's runtime.
|
`BrowserWindow` then you must set `event.newGuest` to reference the new `BrowserWindow`
|
||||||
|
instance, failing to do so may result in unexpected behavior. For example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
myBrowserWindow.webContents.on('new-window', event => {
|
||||||
|
event.preventDefault()
|
||||||
|
const win = new BrowserWindow({ show: false })
|
||||||
|
win.once('ready-to-show', () => win.show())
|
||||||
|
win.loadURL(event.url)
|
||||||
|
event.newGuest = win
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
#### Event: 'will-navigate'
|
#### Event: 'will-navigate'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue