Event when closing tab/browser

Asked

Viewed 188 times

-1

Good guys blz, I wanted to know how to call an event when I close tab or browser and when to close I wanted to update mysql ex: logged in=1, then when it closes update to log in=0

1 answer

1


You could use a beforeunload to call your event before the window closes, although it is not compatible with some browsers.

$(window).on('beforeunload',function(){
    //meu evento
});

An alternative solution would be to send a POST warning to the server that the user is still online, such as:

var online = setInterval(function (){
    //fazer teu post aqui
}, 60000);

So every 60 seconds the user will be updated with the current time, then to check if he is online or not just check if the last time he was seen has more than 60 seconds.

Browser other questions tagged

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