Alert when browser is closed

1

As I would have to alert you to close the browser, I got one, but it also gives the alert when changing the tabs and that's not what I want at the moment ....

Thank you!

    
asked by anonymous 06.05.2015 / 14:40

2 answers

2

I do not know if it helps ... but you can use this method ... the only problem is that it will be executed when doing refresh, etc ...

<script type="text/javascript">
window.onbeforeunload = confirmar_saida;

function confirmar_saida()
{
    return 'Vamos ter saudades suas!';
}
</script>

Olá! :D
    
06.05.2015 / 16:22
1
window.location ao clicar em um botão   
function redirecionar(){ 
    alert("Você será redirecionado"); 
    window.location="sair.php/"; 
}

Or

function funcao() {
 var r = confirm('Quer mesmo sair?');;

 if (r == true) {
    window.location.assign("http://www.globo.com") /* ou o seu sair.php */
 } 
else {
    alert('Nao funcionou');
}
 return false;
}
<a href="#" onclick="return funcao();">Sair do sistema</a>
    
06.05.2015 / 14:46