Consider the following HTML:
<html> <head></head> <body> <input type="text" onblur="window.setTimeout('document.title += 2;', 0);" /> <input type="button" onclick="document.title += 1" /> </body> </html>
[ Demo with 0 delay , 100 ms delay , 150 ms delay ]
And the following steps:
- The user enters an input (focus).
- User clicks a button.
Now the events will occur in the following order:
- Text input blur event.
- Button click event.
Checking this on all available browsers, I get:
document.title = '21' //Expected behavior
But! In the production browser (Windows XP + IE 7) I get:
document.title = '12' //Unexpected behavior
I also tried to simulate it in IE 7 mode on my local machine (IE 10), was not able to play it.
This is obviously a simplified example of the problem I am facing. Otherwise, I could just get rid of setTimeout.
In a real scenario, the call to setTimeout is actually made by a third-party script library (ASP.NET Dev Express components).
Besides the actual solution to this problem (which I think I can handle), what explanation can be applied to this behavior?
Update:
Using the expression new Date().getTime() to get the time of each step that the browser executes. This happens as follows:
1387369361417 //document.title += 1 1387369361433 //document.title += 2