Display something when trying to close my site

9

You can display something (an alert , or popup , an optin grabber newsletter) when the person tries to close my site ?

I've seen something similar, that it displays alert() to confirm if the person wanted to leave or stay on the site . But it only worked in Chrome!

    
asked by anonymous 19.11.2014 / 04:59

1 answer

9

You can use window.onbeforeunload .

So when you close the window you receive a question with the text you choose, for example 'Are you sure you want to close the window?'. You can see the same thing working here in the OS when you close a page with a question or answer that is in the middle of the edit and has not been saved / saved.

window.onbeforeunload = function(e) {
   return 'Tem a certeza que quer fechar a janela?';
};
    
19.11.2014 / 08:38