Does anyone have a good technical reason why the following code runs fine in WebKit based browsers (Chrome/Safari) but causes FF to hang and IE never writes anything out? Note that if i use writeOutDirect() which does not use setTimeout() then it works fine (but has other side effects as i discuss at http://blog.livz.org/post/More-responsive-UI-with-setTimeout-on-WebKit.aspx .
<html>
<head>
<script>
function doIteration() {
for (i=0;i<10;i++) {
writeOut(i);
//writeOutDirect(i);
}
}
function writeOut(i) {
setTimeout(function () {
document.write(i+'<br/>');
},0);
}
function writeOutDirect(i) {
document.write(i+'<br/>');
}
</script>
</head>
<body onload="doIteration()">
</body>
The Gecko behavior here is correct. The WebKit behavior is a bug. See https://bugs.webkit.org/show_bug.cgi?id=65407