Verify that the person will close the site

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?");
}
    
asked by anonymous 29.03.2017 / 15:28

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?");
};
    
29.03.2017 / 15:32