I am following this code
window.addEventListener('beforeunload', function (e) {
// Cancel the event
e.preventDefault(); // If you prevent default behavior in Mozilla Firefox prompt will always
be shown
// Chrome requires returnValue to be set
e.returnValue = '';
});
From https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload
My code is:
<body style="height: 100%; overflow: hidden" onload="return onBodyLoad();">
function onBodyLoad() {
window.addEventListener("beforeunload", function (e) {
alert(1);
document.getElementById("Button1").click();
});
}
I am closing a tab by clicking on the X. My code is not executing. Any idea why?
Thanks