私は、ユーザがページ上でアクティブでない場合、一定時間後にログアウトする必要のあるアプリケーションに取り組んでいます。私は空白の認証トークンを使用していて、1時間で期限切れです。ここで私は2つのタイマーをセットアップしようとしています。最初のタイマーは1分ごとに実行され、すべてのマウスアクションでそれ自体をリセットし続け、2番目のタイマーは58分の休止後にロードして、 。私は機能を望んで得ることができません、最初のタイマーは1分後に実行されますが、同時にそれはまた2番目のタイマーのキック。それは場合に役立ちます私のウェブページでタイムアウトセッションを設定する際に問題がある
ここに私のJavascriptコードは、私が一度サイトで同じ効果を必要と..
<script>
function timerModal() {
var count = 120;
console.log("This has started");
var counter = setInterval(timer, 1000); //1000 will run it every 1 second
function timer() {
count = count - 1;
if (count <= 0) {
$(this).mousemove(function (e) {
count = 120;
});
$(this).keypress(function (e) {
count = 120;
});
clearInterval(counter);
//vmsWebUtils.signOut(); //counter ended, do something here
return;
}
document.getElementById("timer").innerHTML = count + " "; // watch for spelling
console.log(count);
}
}
var idleTime = 0;
$(document).ready(function() {
//Increment the idle time counter every minute.
var idleInterval = setInterval(timerIncrement, 60000); // 1 minute
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).keypress(function (e) {
idleTime = 0;
});
});
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime => 57) { // 57 minutes
$("#sessionTimeout").show();
timerModal();
}
console.log(idleTime);
}
</script>
ここをクリックしてください:http://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly – couzzi