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

198
Visualizações
What is the difference between a mouse event occurring and not occurring after the page is loaded?

I tried to detect a tap close event and get a confirmation message. The code is like this. Strangely, if I close the tab after the mouse event occurs(clicking anywhere), the confirmation message appears normally, but if the mouse event does not occur, the message window does not appear and just appears. What is the difference between a mouse event occurring and not occurring after the page is loaded?

$(function(){
    var validNavigation = false;
    //Attach the event keypress to exclude the F5 refresh (includes normal refresh)
    $(document).bind('keypress', function (e) {
        if (e.keyCode == 116) {
            validNavigation = true;
        }
    });

    // Attach the event click for all links in the page
    $("a").bind("click", function () {
        validNavigation = true;
    });

    // Attach the event submit for all forms in the page
    $("form").bind("submit", function () {
        validNavigation = true;
    });

    // Attach the event click for all inputs in the page
    $("input[type=submit]").bind("click", function () {
        validNavigation = true;
    });

    window.onbeforeunload = function () {
        if (!validNavigation) {
            return "Do you really want to close?"; 
        }
        validNavigation = false;
    };

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