var idleTime = 1;
$(document).ready(function () {
//Increment the idle time counter every minute.
var idleInterval = setInterval(timerIncrement, 5000); // 5 seconds
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
idleTime = 1;
});
$(this).keypress(function (e) {
idleTime = 1;
});
});
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime == 2) { // 10 seconds
alert("10 seconds");
// alert("19分鐘沒動靜!");
}
else if(idleTime == 3) { // 15 seconds
window.location.href = 'http://www.google.com';
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
我想做的是检测空闲时间,如果超过10秒,就会弹出一条警告消息。如果空闲时间一直计数到15秒,页面将直接重定向到该url。
但似乎在发出警报消息后,其余代码并未运行。
最佳答案
alert()函数将停止JS的执行。如果您想与用户沟通以警告他们即将超时,我建议您使用 <div>
制作自己的通知。或类似的东西。
关于javascript - 弹出警报消息后,javascript 是否仍在运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35415930/