One of the biggest problems faced when writing Javascript that modifies the DOM is the fact that the poorly written IE7 crashes because it hasn't finished loading the current element. This only seems to happen when the DOM is modified through a script loaded by an xx:expression binding in a style tag.
The only solution that I managed to find was to set an asynchronous timeout:
setTimeout('function()',500);
and then check if the DOM is loaded inside the function:
var ne = document.body.innerHTML;
if (ne.indexOf('LAST TEXT BEFORE BODY CLOSE TAG') == -1) {
setTimeout('function()',500);
return;
}
Obviously a far from ideal solution!