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

170
Vistas
How to alert user before leaving webpage and run ajax function if user presses "ok"?

I have this function that is supposed to ask the user if they are sure that they want to leave or refresh the website and if they say yes and leave the ajax function is executed. My problem is if the ajax function is alone the user is given no warning but if anything else is in the code the ajax function doesn't work.

<script type="text/javascript">
            window.onbeforeunload = function () {
                return "";
                $.ajax({url: "checkout.php", type : 'post', data : { page_left: 1}});
            }
       </script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

    <script type="text/javascript">
            window.onbeforeunload = function () {
 if (window.confirm("Do you really want to leave?")) {
  $.ajax({url: "checkout.php", type : 'post', data : { page_left: 1}});
} } </script>

Check this will help

about 4 years ago · Juan Pablo Isaza Denunciar
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