Screen Mouse Function

-2

This function that captures the movement of the mouse does not work, what is wrong with it to correct?

    <script>
        $(document).bind("mouseleave", function(e) {
            if (e.pageY - $(window).scrollTop() <= 1) {
                alert('Tem certeza que quer fechar a aba? :(');
            }
        });
    </script>
    
asked by anonymous 02.08.2017 / 04:03

1 answer

0

It's as close as you can get

$(document).mousemove(function(e) {
    // $("body").html("posição do mouse: " + (e.pageY - $(window).scrollTop()))
    if ((e.pageY - $(window).scrollTop()) == 0){
      alert('Tem certeza que quer fechar a aba? :(');
    }
});

// Ou

$(window).mouseleave(function() {
   alert('Tem certeza que quer fechar a aba? :(');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
02.08.2017 / 04:20