setTimeout() firing prematurely when showing an alert() in Chrome
-
11-10-2019 - |
Question
I have the following code:
t = setTimeout(function () { blah(); }, 900000);
Which, basically, calls blah after 15 minutes of the page having loaded.
However, if at some point I show an alert() or a confirm(), then as soon as it is dismissed, blah() gets executed for some reason.
As far as I've seen, this only happens in Safari/Chrome. It doesn't happen in IE/Firefox.
Any ideas what's going on, or even better, how to solve this?
Thanks!
Daniel
Solution
You are not alone, this is the bug: code.google.com/p/chromium/issues/detail?id=43796
OTHER TIPS
This problem has not been solved by the chromium team.
I found that, by introducing some delay between clearTimeout and the setTimeout, will solve the problem.
// mouse event
document.onmousemove = function(){
clearTimeout(timeout);
debug("Idle Timer reinitialized"); // apparently this function introduces some delay. it just works. You may want to include another timer here like for 2-3 seconds.
timeout = setTimeout(logoutNow, systemTimeout);
}
hope it helps.
Are you sure that is the cause, I ran this demo and can not replicate it.
"Timeout!" will appear after 10 seconds, click in the box before hand to test.