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

104
Views
How to accept onbeforeunload programatically

I am using window.onbeforeunload to call socket before my page unloads, onbeforeunload shows a pop-up to confirm 'if we want to leave the page'. I want my JavaScript code to auto check the condition and don't show me the alert on the browser and leave the page automatically.

My code-

<div ng-app="myApp" ng-controller="myCtrl">
    <button ng-click="redirect()">Redirect to google</button>
</div>
<script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
        $scope.redirect=()=>{
            window.location.href="https://google.com";
        }
    });
</script>
<script>
window.onbeforeunload = (e) => {
console.log("before unloading the page");
return "";
};
</script>

How can I stop showing the alert whenever I click to redirect button!!

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!