Merge pull request #8651 from electron/new-window-docs
[ci skip] Improve docs for `new-window` event
This commit is contained in:
commit
b92c4f6ce5
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, url) => {
|
||||||
|
event.preventDefault()
|
||||||
|
const win = new BrowserWindow({show: false})
|
||||||
|
win.once('ready-to-show', () => win.show())
|
||||||
|
win.loadURL(url)
|
||||||
|
event.newGuest = win
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
#### Event: 'will-navigate'
|
#### Event: 'will-navigate'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue