minor fixes
This commit is contained in:
parent
9dc5f3e949
commit
91e9b9c237
1 changed files with 20 additions and 0 deletions
|
@ -185,6 +185,26 @@ window.onbeforeunload = function() {
|
|||
|
||||
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.
|
||||
|
||||
````warn header="The `event.preventDefault()` doesn't work from a `beforeunload` handler"
|
||||
That may sound weird, but most browsers ignore `event.preventDefault()`.
|
||||
|
||||
Which means, following code may not work:
|
||||
```js run
|
||||
window.addEventListener("beforeunload", (event) => {
|
||||
// doesn't work, so this event handler doesn't do anything
|
||||
event.preventDefault();
|
||||
});
|
||||
```
|
||||
|
||||
Instead, in such handlers one should set `event.returnValue` to a string to get the result similar to the code above:
|
||||
```js run
|
||||
window.addEventListener("beforeunload", (event) => {
|
||||
// same as returning from window.onbeforeunload
|
||||
event.returnValue = "There are unsaved changes. Leave now?";
|
||||
});
|
||||
```
|
||||
````
|
||||
|
||||
## readyState
|
||||
|
||||
What happens if we set the `DOMContentLoaded` handler after the document is loaded?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue