我对关闭浏览器窗口有一点问题,
基本上,我有一个页面,我想在 15 分钟不活动后关闭它。我已经设法制作了一个计时器,它会在不活动 10 分钟后提醒窗口。
我需要的是,在计时器完成时,会出现一个带有可见倒计时的弹出/警报,用户可以从这里继续他的会话或结束它。如果用户在 5 分钟内未单击继续或忽略弹出窗口,则弹出窗口和父窗口都将关闭。否则,如果用户按下继续,弹出窗口将关闭并刷新主页(从而再次启动计时器)有什么建议吗?这是我的代码:
var idleTime = 0;
var activeTime = 0;
var warningFlag = 0;
var loginTime = new Date();
var logoutTime = loginTime;
setInterval(function checkIdle() {
idleTime += 1;
activeTime += 1;
if(idleTime > 10) {
alert("You've been inactive for 10 \n minutes, are you still there ?\nYou logged in at " + loginTime);
warningFlag=1;
}
if((idleTime > 15) && (warningFlag==1)) {
alert("You've been logged out due to inactivity for 15 \n minutes? \nYou logged out at " + logoutTime);
window.close();
}
window.onload = resetTimer;
document.onmousemove = resetTimer;
document.onkeypress = resetTimer;
},1000);
function resetTimer() {
idleTime = 0;
}