Hi Guys,
Is there a way to destroy session if browser/tab is closed?
Found this js online it works but if the refresh button in the browser is pressed it will destroy the session and logout the user, Is there any alternative for this? or is there a way to add a function that will detect if the refresh button is pressed?
var validNavigation = false;
function endSession() {
$.get(“logout.php”);
}
function wireUpEvents() {
window.onbeforeunload = function() {
if (!validNavigation) {
endSession();
}
}
$(document).bind(‘keypress’, function(e) {
if (e.keyCode == 116){
validNavigation = true;
}
});
$(“a”).bind(“click”, function() {
validNavigation = true;
});
$(“form”).bind(“submit”, function() {
validNavigation = true;
});
$(“input[type=button]”).bind(“click”, function() {
validNavigation = true;
});
}
$(document).ready(function() {
wireUpEvents();
});