質問は静かに奇妙に聞こえますが、ここに問題があります。次のコードは完全に機能します。タイマーは 30 分で開始し、マウスの動きが検出されない 1 秒ごとにタイマーがカウントダウンされます。マウスの動きが検出されると、タイマーが 30 分にリセットされ、ページの非アクティブ状態が 25 分経過した時点で、CSS ポップアップに最後の 5 分間のカウントダウンが表示され、30 分でユーザーは自動ログアウトされます。ただし、ユーザーがページを開いたまま別の Web ページをアクティブに表示している場合、ブラウザーによっては、タイマーが遅くなったり、完全に停止したりします。実際には、スクリプトを完全に否定します。スクリプトで通常のカウントダウンを続行し、ページをアクティブに表示していない場合でもユーザーを強制的にページから追い出すことはできますか? それとも、メモリ負荷を軽減するためのこれらのブラウザーの癖ですか?
var Timing = 0;
var CounterTime = 0;
var TimePast = 0;
var Seconds = 1800;
var Warn = 1500;
var MinuteLeft = 30;
var SecondLeft = 60;
var StopRefresh = 0;
function ResponseTime()
{
Timing = Timing + 100;
CounterTime = CounterTime + 100;
if(Timing % 1000 == 0)
{
TimePast = TimePast + 1;
SecondLeft = SecondLeft - 1;
if(SecondLeft == 59)
{
MinuteLeft = MinuteLeft-1;
}
if(SecondLeft == 0)
{
SecondLeft = 60;
}
}
if(MinuteLeft != 0)
{
if(SecondLeft == 60)
{
document.getElementById('CountdownTimer').firstChild.nodeValue = MinuteLeft+":00";
}else if(SecondLeft < 10)
{
document.getElementById('CountdownTimer').firstChild.nodeValue = MinuteLeft+":0"+SecondLeft;
}else
{
document.getElementById('CountdownTimer').firstChild.nodeValue = MinuteLeft+":"+SecondLeft;
}
if((MinuteLeft == 0) && (SecondLeft <= 10))
{
document.getElementById('CountdownTimer').style.fontWeight = "bolder";
document.getElementById('CountdownTimer').style.color = "red";
}
document.getElementById('CountdownTimer').style.fontWeight = "normal";
document.getElementById('CountdownTimer').style.color = "black";
}else
{
document.getElementById('CountdownTimer').firstChild.nodeValue = SecondLeft;
if((MinuteLeft == 0) && (SecondLeft <= 10))
{
document.getElementById('CountdownTimer').style.fontWeight = "bolder";
document.getElementById('CountdownTimer').style.color = "red";
}else
{
document.getElementById('CountdownTimer').style.fontWeight = "normal";
document.getElementById('CountdownTimer').style.color = "black";
}
}
if(TimePast == 1800)
{
document.getElementById('DoLogoutRequest').submit();
}
if(MinuteLeft <=4)
{
document.getElementById('Overlay').style.visibility="visible";
document.getElementById('ForceLogout').style.visibility="visible";
}else
{
document.getElementById('Overlay').style.visibility="hidden";
document.getElementById('ForceLogout').style.visibility="hidden";
}
$(document).ready(function(){
$(document).mousemove(function(){
Timing = 0;
TimePast = 0;
SecondLeft = 60;
MinuteLeft = 29;
});
});
}