Event when the user leaves the page

1

I would like to make a model the same as the free ratra site. How could I do this? If it consists of when the mouse leaves the page a alert appears asking if the user really wants to leave the page. What javascript event does this anyone know?

    
asked by anonymous 04.11.2015 / 17:17

2 answers

1

I believe you are looking for this event:

window.onbeforeunload = function(){return "Deseja mesmo sair do site?"};

This will display a confirmation window when the user clicks to close the tab.

    
04.11.2015 / 17:42
0

Although the question was from a long time ago, I realized that I did not have any answers that really answered the question, so for those who have the same doubt and end up falling into this post.

Just use the mouseleave of JQuery event in body .

$('body').mouseleave(function(){
    alert('O Usuário tirou o mouse da página');
})

Instead of the alert you do whatever is necessary, such as putting a pop up to "hold" the user on the page.

    
26.07.2018 / 16:24