我在空闲库中有这个功能,但我需要以秒为单位计算动作时间,我的意思是活动时间(onclick,onscroll 和 keypress)。
功能是:
(function () {
var minutes = false;
var interval = 1000;
var IDLE_TIMEOUT = 5;
var idleCounter = 0;
var counter=0;
document.onclick = document.onkeypress = function () {
idleCounter = 0;
setInterval(function () {
++counter;;
}, 1000);
};
window.setInterval(function () {
if (++idleCounter >= IDLE_TIMEOUT) {
alert(counter);
document.location.href = "SessionExpired.aspx";
}
}, interval);
}());
这个函数会等待 5 秒,如果页面上没有任何动作,所以我会被重定向到 SessionExpired.aspx。如果有动作,那么每秒都在做++couter。
我需要这个计数器在几秒钟内。
谢谢你。