‘Image’ is undefined Javascript Error in IE

The built-in browser object "Image" is sometimes reported as undefined on pages viewed in IE. I've done extensive research online, but all leads point to browser addons/plugin in combination of calling that page in a pop-up window as the likely culprit. No solutions were found and I'm feeling that none were ever offered.

This error seems to be triggered by the JavaScript expression, "new Image" as in the following statement:

var myImage = new Image();

I'm stumped. Why would IE complain about a built-in object? It doesn't make sense.

document.write and dynamic script injection in Internet Explorer

I have recently run into an issue in all versions of IE (i.e. IE6, IE7 and IE8) when I used document.write to insert a Javascript file onto the page. This is what I was trying to accomplish:

<script type="text/javascript">
document.write('<div id="ad1" style="display:none;">');
document.write('<script type="text/javascript" src="http://someadagency.com/somead?params"><\/script>');

The problems was that in IE, this is what I get:

<div id="ad1" style="display:none;"></div>[ad content]

Where in Firefox and Safari, I get:

<div id="ad1" style="display:none;">[ad content]</div>

Which is the expected behavior I want. After plenty of online research, I found out that IE defers the processing of any script tag inserted in the document using document.write until it's done processing the parent script tag. To circumvent this problem, I externalized the markup I wanted to wrap the ad in and now my cross-browser solution is:

<script type="text/javascript">
document.write('<script type="text/javascript" src="http://mydomain.com/js/pre_ad_wrapper.js"><\/script>');
document.write('<script type="text/javascript" src="http://someadagency.com/somead?params"><\/script>');
document.write('<script type="text/javascript" src="http://mydomain.com/js/post_ad_wrapper.js"><\/script>');

Where the content of the two files is basically the one-line document.write statement spitting out the wrapping markup.

I'm using this technique to load in 3rd-party ads at the bottom of the page and relocating them to their propers spots on window load. This has proved to be a major performance boost, especially combined with the other techniques we're using to renders the page.