0

My understanding is that Javascript timers are paused when there is an alert dialog open. I see this behavior in Chrome, Safari, and IE. However, in Firefox it appears that the timers are not paused. Instead, they continue to count down and then when you come out of the alert() dialogue the function executes right away.

Is this expected behavior in Firefox? Is there an ECMA standard for how to deal with timers when there is user intervention? Most importantly, is there a way to standardize this across browsers?

Example JSFiddle to try running in different browsers: http://jsfiddle.net/DuncanMack/p1h5769b/

setTimeout(function() {
    alert("There should be a two second pause before I come up after you close the previous window");
},2000);

alert("Will I stop event timers? It appears to depend on the browser. Hang out in this window for a while and then see if the next alert dialog comes right up or if you have two wait 2 seconds");
DuncanMack
  • 311
  • 3
  • 17
  • I can see why that question may seem similar, but the purpose of my question is that on Firefox the alert window is, in fact, non-blocking, which is not what would I would expect. The issue that I'm trying to address (with Microsoft's unobtrusive ajax library) actually benefits from the blocking behavior. – DuncanMack May 15 '15 at 20:03
  • Even in FF, the alert is blocking, because the second alert can't happen while it's waiting. The difference is whether timeouts count the time while the browser is blocked in the alert. I'm not sure why you would expect the clock to stop during an alert, so FF's behavior seems correct to me. – Barmar May 15 '15 at 20:15
  • I agree -- I was surprised that timers would be stopped while there is a dialog open. But in all other browsers they are and it's this discrepancy that's causing problems (outside the scope of this question). – DuncanMack May 15 '15 at 20:34
  • 1
    Found this related question http://stackoverflow.com/questions/6084410/asynchronous-timer-event-running-synchronously-buggy-in-firefox-4. The answer suggests that FF worked like the others in FF 3, but it was changed in FF 4 to the current behavior. – Barmar May 15 '15 at 20:38
  • Another related question: http://stackoverflow.com/questions/5194231/how-to-keep-timer-running-when-alert-is-displayed-in-javascript – Barmar May 15 '15 at 20:40
  • I think the best answer is not to use `alert()`, use HTML dialogs. – Barmar May 15 '15 at 20:41

0 Answers0