Idle ライブラリにこの関数がありますが、アクション時間を秒単位で計算する必要があります。つまり、アクティブ時間 (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 にリダイレクトされます。アクションがある場合は、毎秒 ++counter を実行しています。
このカウンターが秒単位で必要な場合。
ありがとうございました。