Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda