私の Web ページには、Javascript の を使用したカウントダウン タイマーがありsetTimeout()
ます。
function Tick() {
if (RemainingSeconds <= 0) {
alert("Time is up.");
return;
}
RemainingSeconds -= 1;
ElapsedSeconds += 1;
UpdateTimerDisplay();
window.setTimeout("Tick()", 1000);
}
onbeforeunload
また、ユーザーがページを離れるのを「防ぐ」ためにトリガーされる機能もあります。
window.onbeforeunload = function () {
if (!isIEAjaxRequest) {
return "You should use the logout button to leave this page!";
}
else {
isIEAjaxRequest = false;
}
};
問題は、「このページを離れてもよろしいですか?」ウィンドウがプロンプトを表示すると、setTimeout()
機能が一時停止します。これを防ぐ方法について何か考えはありますか?