Check if the person will close the site

Asked

Viewed 59 times

2

Is there any way to check if the person’s mouse is going to close the site? With Javascript, etc... In the simplest case:

if(estaindofechar){
  alert("Tem certeza?");
}

1 answer

5


This is the method called when the user tries to exit the page

window.onbeforeunload = function(e) {
    return confirm("Você tem certeza que deseja fechar a página?");
};
  • Thanks Luks, but is there any way in the script to identify if the mouse is almost getting close to where the button to close the la tab? I’ve seen that function but I don’t know how it’s done...

  • In this case you have to implement a little more JS by identifying the point where the cursor is on the screen

Browser other questions tagged

You are not signed in. Login or sign up in order to post.