Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

94
Views
Beforeunload is not detected

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!