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

488
Views
¿Cómo deshabilitar la acción beforeunload cuando el usuario está enviando un formulario?

Tengo este pequeño fragmento de código:

 <script> $(window).bind('beforeunload', function() { $.ajax({ async: false, type: 'POST', url: '/something' }); }); </script>

Me pregunto, ¿cómo podría deshabilitar esta solicitud cuando el usuario presiona el botón Enviar?

Básicamente algo como aquí, en SO. Cuando hace una pregunta y decide cerrar la página, aparece una ventana de advertencia, pero eso no sucede cuando envía el formulario.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Llame a unbind usando el controlador de eventos beforeunload :

 $('form#someForm').submit(function() { $(window).unbind('beforeunload'); });

Para evitar que se envíe el formulario, agregue la siguiente línea:

 return false;
over 4 years ago · Santiago Trujillo Report

0

Usar

 $('form').submit(function () { window.onbeforeunload = null; });

¡Asegúrese de tener esto antes de la función de envío principal! (Si alguna)

over 4 years ago · Santiago Trujillo Report

0

Esto es lo que usamos:

En el documento listo llamamos a la función beforeunload.

 $(document).ready(function(){ $(window).bind("beforeunload", function(){ return(false); }); });

Antes de cualquier envío o recarga de ubicación, desvinculamos la variable.

 $(window).unbind('beforeunload'); formXXX.submit(); $(window).unbind("beforeunload"); location.reload(true);
over 4 years ago · Santiago Trujillo Report
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!