mirror of
https://github.com/electron/electron.git
synced 2026-01-09 15:38:08 -05:00
Improve docs on window.open
This commit is contained in:
@@ -50,8 +50,16 @@ Native `window.open()` allows synchronous access to opened windows so it is conv
|
|||||||
The creation of the `BrowserWindow` is customizable in `WebContents`'s `new-window` event.
|
The creation of the `BrowserWindow` is customizable in `WebContents`'s `new-window` event.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
// main process
|
||||||
|
const mainWindow = new BrowserWindow({
|
||||||
|
width: 800,
|
||||||
|
height: 600,
|
||||||
|
webPreferences: {
|
||||||
|
nativeWindowOpen: true
|
||||||
|
}
|
||||||
|
})
|
||||||
mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => {
|
mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => {
|
||||||
if (url.endsWith('modal.html')) {
|
if (frameName === 'modal') {
|
||||||
// open window as modal
|
// open window as modal
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
Object.assign(options, {
|
Object.assign(options, {
|
||||||
@@ -65,3 +73,9 @@ mainWindow.webContents.on('new-window', (event, url, frameName, disposition, opt
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// renderer process (mainWindow)
|
||||||
|
let modal = window.open('', 'modal')
|
||||||
|
modal.document.write('<h1>Hello</h1>')
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user