A piece of javascript code I'm working on is causing the nasty "Operation Aborted" message in IE. I am well aware that you cannot modify the DOM until after it has loaded. Sure enough the line of javascript code causing the error is the one which appends a new div tag to the body. However the function which the line is located within is called via FastInit.addOnLoad! I thought this meant the function would be called after the DOM was ready. Is there a better solution to this problem that using FastInit?
+1
A:
I'm not sure about FastInit, but I just answered a similar question about waiting for the DOM to be ready here:
Basically, you can do it in IE by using the defer attribute on your script tag:
<script type="text/javascript" defer>
</script>
This will delay parsing the script until after the DOM is ready.
Andy E
2009-07-20 14:45:33
@Andy, thanks, I'll try that.
Josh
2009-07-20 14:55:17
@Josh: fastInit already uses that trick to work out when to trigger on IE: you can see it at the bottom of the FastInit source in a "document.write".
NickFitz
2009-07-20 17:16:34
@NickFitz: that's what I thought -- which is why I was confused as to why this isn't working.
Josh
2009-07-20 17:52:51
@Andy, unfortunately, the defer tag didn't help.
Josh
2009-07-24 16:08:40
I'd prefer not to wait until all images have loaded. Also, when I do window.onload, sometimes my code is never actually run!
Josh
2009-07-20 14:54:40
A:
NickFitz
2009-07-20 16:59:57
The script in questions is in the <head> and is called via FastInit so the DOM should be ready already.
Josh
2009-07-20 17:01:57
FastInit has to use some pretty weird tricks to get a simulation of DOMready on IE. The definitive Microsoft explanation of the causes for this error is at http://support.microsoft.com/kb/927917
NickFitz
2009-07-20 17:14:44
@NickFitz: The Microsoft document seems to refer to scripts that are grandchildren (or deeper) of the body. My script is a child of the <head> tag. Are you saying my script should be a child of the <body> tag instead? It appears to me that article doesn't apply in this case.
Josh
2009-07-20 17:54:29
@NickFitz putting the script in the body tag didn't help, unless it was the very last item in the DOM.
Josh
2009-07-24 22:25:26
I ended up just putting the script tag as the final element in the DOM... still don't know why this wasn't work in the first place.
Josh
2009-08-25 19:16:59