On my webpage, I have a countdown timer using javascript setTimeout() .
function Tick() { if (RemainingSeconds <= 0) { alert("Time is up."); return; } RemainingSeconds -= 1; ElapsedSeconds += 1; UpdateTimerDisplay(); window.setTimeout("Tick()", 1000); }
I also have a function running on onbeforeunload to “prevent” a user leaving the page.
window.onbeforeunload = function () { if (!isIEAjaxRequest) { return "You should use the logout button to leave this page!"; } else { isIEAjaxRequest = false; } };
The problem is that when "Are you sure you want to leave this page?" window, it pauses the setTimeout() function. Any thoughts on how to prevent this?
source share