var myclose = false;
$(window).on('beforeunload', function(){
var messege = 'You have closed the browser. Do you want to logout from your application?';
setTimeout('myclose=false',10);
myclose=true;
return myclose;
});
$(window).on('onunload', function(){
if (myclose==true)
{
//the url of your logout page which invalidate session on logout
alert('hello');
location.replace('logout.php') ;
}
});
var myclose = false;
$(window).on('beforeunload', function(){
var messege = 'You have closed the browser. Do you want to logout from your application?';
setTimeout('myclose=false',10);
myclose=true;
return myclose;
});
$(window).on('onunload', function(){
if (myclose==true)
{
//the url of your logout page which invalidate session on logout
alert('hello');
location.replace('logout.php') ;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>