Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda