Minor updates to example

* const-ing
* mainWindow -> win
* add dialog require
This commit is contained in:
Kevin Sawicki 2017-05-11 09:01:51 -07:00 committed by GitHub
parent 4044548f3e
commit 4e1943dfe6

View file

@ -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()
} }