Log out when browser close or log out

Asked

Viewed 280 times

2

I’m developing a system that stores in the database when user logs in and out. However, the logout function is only called when the user clicks out.

I was wondering if you can call the logout function when the browser closes or the session ends.

  • If the above linked solution or answer below does not resolve, please [Dit] post by further detailing the peculiarities and requirements of your case.

1 answer

1


You could try using the 'onunload' function'

<body onunload="funcaoEventoSair()">

<script>
function funcaoEventoSair() {
    alert("SAIR"); // colocar sua lógica de log off aqui 
}
</script>

another alternative:

<script>
window.onbeforeunload = function(){
        alert("SAIR"); // colocar sua lógica de log off aqui 
}
</script>

Browser other questions tagged

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