minor fixes

This commit is contained in:
Ilya Kantor 2021-10-25 22:34:12 +03:00
parent 9dc5f3e949
commit 91e9b9c237

View file

@ -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. 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 ## readyState
What happens if we set the `DOMContentLoaded` handler after the document is loaded? What happens if we set the `DOMContentLoaded` handler after the document is loaded?