I'm trying to warn the user before reloading or closing the page, but the problem is that it works on reloading page but not on closing the page.
Here is the Javascript code I'm using :
window.onbeforeunload = function(e) {
var dialogText = 'Dialog text here';
e.returnValue = dialogText;
return dialogText;
};
This works when reloading the page but it does not work when closing the page I've even tried :
window.onunload = function(e) {
var dialogText = 'Dialog text here';
e.returnValue = dialogText;
return dialogText;
};
And
window.addEventListener('unload', myFunc, false);
But does not work either. Thanks to everyone for helping.