Javascript Commands Not Executed In Order In Safari
I discovered this bug while dealing with another issue. The order of JavaScript commands listed is different than the order of their execution in Safari: Example: alert('here'); do
Solution 1:
I don't think that's a bug, strictly speaking. It's just that it's all synchronous, and there was no repaint before the second alert. Repaints don't usually happen within the same "tick" of the browser's event loop (although document.write
seems to force a repaint in other browsers, e.g. Chrome).
This (ugly) workaround should fix it:
alert('here');
document.write('This is the hidden message.');
setTimeout(function() {
alert('You should be seeing the hidden message by now.');
}, 0);
Solution 2:
Try this, if you have jQuery: http://jsfiddle.net/2Kcuz/
Per my comment, my guess is the text you added with document.write
simply hasn't rendered yet (but it's there nonetheless).
Post a Comment for "Javascript Commands Not Executed In Order In Safari"