Skip to content

Commit bb153ee

Browse files
authored
update browser-window.md
Add a note about the subtle difference between `window.onbeforeunload = handler` and `window.addEventListener('beforeunload', handler)`.
1 parent 6a93052 commit bb153ee

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

docs/api/browser-window.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,10 @@ window.onbeforeunload = (e) => {
410410
// a non-void value will silently cancel the close.
411411
// It is recommended to use the dialog API to let the user confirm closing the
412412
// application.
413-
e.returnValue = false
413+
 e.returnValue = false // equivalent to `return false` but not recommended
414414
}
415415
```
416+
_**Note**: There is a subtle difference between the behaviors of `window.onbeforeunload = handler` and `window.addEventListener('beforeunload', handler)`. It is recommended to always set the `event.returnValue` explicitly, instead of just returning a value, as the former works more consistently within Electron._
416417

417418
#### Event: 'closed'
418419

0 commit comments

Comments
 (0)