estoy siguiendo este codigo
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 = ''; });De https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload
mi código es:
<body style="height: 100%; overflow: hidden" onload="return onBodyLoad();"> function onBodyLoad() { window.addEventListener("beforeunload", function (e) { alert(1); document.getElementById("Button1").click(); }); }Estoy cerrando una pestaña haciendo clic en la X. Mi código no se está ejecutando. ¿Alguna idea de por qué?
Gracias