The order of alter() triggered is:
- Body 1
- Body 2
- Body 3
- On load
By the way, it is tested on both MSIE 6SP1 and Mozilla 1.4, and in the case of MSIE, the alert dialog box of "Body 2" is actually around 50 pixels lower and further to the right, comparing with other alerts triggered. On Mozilla 1.4, there is no difference.
Here is some changes to the HTML document:
Now, Mozilla 1.4 will continue to print out "Body 1", "Body 2" and "Body 3" in order, but MSIE 6SP1 will honour the defer="true" attribute and print out "Body 1", "Body 3" and "Body 2", and then finally "On Load". If defer="true" attribute is not specified, then both Mozilla and MSIE will bring out the alerts in the order they are in the document.
I think MSIE's behaviour is actually correct by asynchronously deferring operations that might be blocked on IO. I guess it makes more sense to Win32 developers as they are used to event driven networking programming. That also implies that MSIE might finish parsing the main document faster than Mozilla if there are a lot of external scripts linked over slow network. Obviously, parsing HTML document and displaying them involves much more than the network programming model, but here's just a little thought on the implication.
Back to more coding...