Parallel alert boxes in Firefox

A combination of setTimeout() and alert() will generate multiple alert boxes.

Click to generate an alert box after a 2-second delay
Click to reset count

What it does

By clicking the link multiple times in rapid succession (less than 2 seconds), you will generate a collection of alert boxes in parallel. setTimeout() executes after the current thread finishes, and alert() blocks the thread. What is the proper behavior?

Things to try

After each test, click the reset link or refresh the page.

The following results are for Firefox on Win XP. FF on Linux behaves differently.

More fun with alert() and setTimeout()

setTimeout() behavior

Does your browser interrupt the current thread to run setTimeout? Click here to check. An alert with a number less than 100000 indicates setTimeout waited for the busy-loop to finish. (All five listed below showed an alert with the number 100000.)

Automatic parallel alerts

Paste this link into the address bar of various browsers. It will generate 5 alert boxes.

Behaviors observed:

  1. Sequential alerts. Each appears after the previous is closed. Modal until last is closed.
  2. Rapidly appear in parallel. Modal until any one of them is closed.
  3. Rapidly appear in parallel. Each may be focused, but only the highest-numbered one (latest) may be closed at any given time. Page cannot be interacted with until all have been closed. Sometimes one of the boxes does not appear right away. You'll see 1,2,3,5. Once 5 is closed, 4 appears.

Who does what (color-assisted):

  1. IE 6 (XP): behavior #1
  2. IE 7 (XP): behavior #1
  3. Opera 9.25 (XP): behavior #1
  4. Safari (webkit nightly) 3.0.4 (XP): behavior #1
  5. Firefox 2.0.0.12 (XP): behavior #2
  6. Firefox 2.0.0.12 (Ubuntu Gutsy): behavior #3

This would indicate that most browsers consider alert() to be truly blocking, whereas Firefox does not.