以下是我闲置10分钟后用于注销用户的代码。
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'); ?>";
}
关于关闭浏览器时的退出操作,也可以通过执行$config['sess_expiration'] = 0;
但是现在我想在关闭选项卡时执行此操作,所以我尝试了以下代码:-
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);
但是它不起作用。我正在使用Chrome 71.0.3578.98。任何帮助将不胜感激。提前致谢。