Minor updates to example
* const-ing * mainWindow -> win * add dialog require
This commit is contained in:
parent
4044548f3e
commit
4e1943dfe6
1 changed files with 4 additions and 4 deletions
|
@ -230,10 +230,10 @@ Calling `event.preventDefault()` will ignore the `beforeunload` event handler
|
||||||
and allow the page to be unloaded.
|
and allow the page to be unloaded.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const {BrowserWindow} = require('electron')
|
const {BrowserWindow, dialog} = require('electron')
|
||||||
let win = new BrowserWindow({width: 800, height: 600})
|
const win = new BrowserWindow({width: 800, height: 600})
|
||||||
win.webContents.on('will-prevent-unload', (event) => {
|
win.webContents.on('will-prevent-unload', (event) => {
|
||||||
let choice = dialog.showMessageBox(mainWindow, {
|
const choice = dialog.showMessageBox(win, {
|
||||||
type: 'question',
|
type: 'question',
|
||||||
buttons: ['Leave', 'Stay'],
|
buttons: ['Leave', 'Stay'],
|
||||||
title: 'Do you want to leave this site?',
|
title: 'Do you want to leave this site?',
|
||||||
|
@ -241,7 +241,7 @@ win.webContents.on('will-prevent-unload', (event) => {
|
||||||
defaultId: 0,
|
defaultId: 0,
|
||||||
cancelId: 1
|
cancelId: 1
|
||||||
})
|
})
|
||||||
let leave = (choice === 0)
|
const leave = (choice === 0)
|
||||||
if (leave) {
|
if (leave) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue