Rain Lover
07-30-2014, 07:50 AM
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) (http://msdn.microsoft.com/en-us/library/ie/ms536907(v=vs.85).aspx)
onbeforeunload event | beforeunload event JavaScript (http://help.dottoro.com/ljhtbtum.php)
javascript - How can I override the OnBeforeUnload dialog and replace it with my own? - Stack Overflow (http://stackoverflow.com/a/276739/478018)
But on MDN (https://developer.mozilla.org/en-US/docs/Web/API/Window.onbeforeunload#Example) 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 '';
window.onbeforeunload = function () {
return 'You might lose your data!';
};
For example:
beforeunload | onbeforeunload event (Internet Explorer) (http://msdn.microsoft.com/en-us/library/ie/ms536907(v=vs.85).aspx)
onbeforeunload event | beforeunload event JavaScript (http://help.dottoro.com/ljhtbtum.php)
javascript - How can I override the OnBeforeUnload dialog and replace it with my own? - Stack Overflow (http://stackoverflow.com/a/276739/478018)
But on MDN (https://developer.mozilla.org/en-US/docs/Web/API/Window.onbeforeunload#Example) 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 '';