Following is my code that I'm using to logout user after 10 mins of inactivity.
var timer = 0;
function set_interval() {
timer = setInterval("auto_logout()", 300000);
}
function reset_interval() {
if (timer != 0) {
clearInterval(timer);
timer = 0;
timer = setInterval("auto_logout()", 300000);
}
}
function auto_logout() {
window.location = "<?php echo base_url('staff/staff_logout'); ?>";
}
As for the logging out when browser closes that also has been taken care in the config.php file by doing $config['sess_expiration'] = 0;
But now I want to do it when a tab is closed so I tried the following code:-
var unloadEvent = function (e) {
var confirmationMessage = "Warning: Leaving this page will result in any unsaved data being lost. Are you sure you wish to continue?";
return confirmationMessage;
};
window.addEventListener("beforeunload", unloadEvent);
But it's not working. I'm using Chrome 71.0.3578.98. Any help will be appreciated. thanks in advance.