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.
- Trigger 3 parallel alerts. An alert box will appear with "#0", then be covered by #1, then #2. Close each to reveal the one preceding it.
- Trigger 1 alert. Notice that you cannot trigger any more until the alert is closed.
- Trigger 2 parallel alerts. Close #1. Even though #0 is still open, you can interact with the page. Trigger another alert (#2) to prove it. Close all.
- Trigger 2 parallel alerts. Move #1 aside, and close #0. Again, you can interact with the page. Trigger another alert (#2) to prove it. Close all.
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:
- Sequential alerts. Each appears after the previous is closed. Modal until last is closed.
- Rapidly appear in parallel. Modal until any one of them is closed.
- 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):
- IE 6 (XP): behavior #1
- IE 7 (XP): behavior #1
- Opera 9.25 (XP): behavior #1
- Safari (webkit nightly) 3.0.4 (XP): behavior #1
- Firefox 2.0.0.12 (XP): behavior #2
- 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.