Skip to content

Commit 91e9b9c

Browse files
committed
minor fixes
1 parent 9dc5f3e commit 91e9b9c

File tree

1 file changed

+20
-0
lines changed
  • 2-ui/5-loading/01-onload-ondomcontentloaded

1 file changed

+20
-0
lines changed

2-ui/5-loading/01-onload-ondomcontentloaded/article.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,26 @@ window.onbeforeunload = function() {
185185

186186
The behavior was changed, because some webmasters abused this event handler by showing misleading and annoying messages. So right now old browsers still may show it as a message, but aside of that -- there's no way to customize the message shown to the user.
187187

188+
````warn header="The `event.preventDefault()` doesn't work from a `beforeunload` handler"
189+
That may sound weird, but most browsers ignore `event.preventDefault()`.
190+
191+
Which means, following code may not work:
192+
```js run
193+
window.addEventListener("beforeunload", (event) => {
194+
// doesn't work, so this event handler doesn't do anything
195+
event.preventDefault();
196+
});
197+
```
198+
199+
Instead, in such handlers one should set `event.returnValue` to a string to get the result similar to the code above:
200+
```js run
201+
window.addEventListener("beforeunload", (event) => {
202+
// same as returning from window.onbeforeunload
203+
event.returnValue = "There are unsaved changes. Leave now?";
204+
});
205+
```
206+
````
207+
188208
## readyState
189209
190210
What happens if we set the `DOMContentLoaded` handler after the document is loaded?

0 commit comments

Comments
 (0)