I’m trying to write a function that shows if a user is logged in or not. The function should make a change in the database when a user leaves the site , and this is my current code:
$(window).bind('beforeunload', function(){
$.ajax({
url: "change_to_logged_out.php",
success: function(data){
alert(data)
}
});
});
The code isn’t executed when the user reloads the page, which is what I want, but is executed when someone closes the tab or the window, also good. But if the user just clicks on a link redirecting to another page on my site, the code is executed. How can I make so that the function ignores if the user clicks on a link to somewhere else on the site, but not if the user is redirected to a different site? Maybe there’s a better way to make a function like this?
Thanks in advance
External selector was taken from here: http://james.padolsey.com/javascript/extending-jquerys-selector-capabilities/