Q1: I have seen the following code in most sources:
window.onbeforeunload = function () {
return 'You might lose your data!';
};
For example:
- beforeunload | onbeforeunload event (Internet Explorer)
- onbeforeunload event | beforeunload event JavaScript
- javascript - How can I override the OnBeforeUnload dialog and replace it with my own? - Stack Overflow
But on MDN the function has an extra parameter: (e)
. Why is that, what is the difference, and which is right?
Q2: It seems that any browser has a default confirmation message that you cannot customize. Chrome, for example, displays:
Are you sure you want to leave this page?
Can I content myself to this message and leave the return
value empty:
return '';