Javascript document.write in IE 8

This is doing my head in, been chasing it all day. We have an ad server that calls a script on our site which then inserts code.

E.g. Adserver page called in an iframe:

<script src="http://adserver/ad?s=728x90"></script>

The javascript returned by the script call above:

document.write('<script type=\'text/javascript\' src=\'\'>\n');
document.write('<script type=\'text/javascript\'>\n');
document.write('<script type=\'text/javascript\'>\n');
document.write('<script type=\'text/javascript\'>\n');
document.write('GA_googleFillSlotWithSize("ca-pub-xxxxxxxxxxxxxxxxxx", "Global_728x90", 728, 90);\n');

This inserts Google Ad Manager ads onto our page. Problem is that the code doesn't work in IE 7 and 8, but works fine in Chrome, Firefox, Safari etc.

The "error" returned by IE is "Object Expected" and running it through IE's "Developer tools" doesn't help either.

I've tried a ton of things to get it working, splitting up the

It seems the error is happening whenever a GS_ or GA_ function is run, so I suspect IE is trying to stop external scripts from writing to the page?

Can anyone shed some light why the error is happening or a solution?



I think it's simply because Chrome, Firefox, Safari etc., are faster browsers. They're downloading the file before executing the script that depends on it, whereas IE is still pulling the file at that point. Perhaps you can include the contents of that js file in your own js somewhere?

I've seen this a lot since posting this question. As far as I understand it, it's a race condition problem that only exists in IE. Unfortunately there is no way around it.

Need Your Help

Change background color of UIButton when Highlighted

iphone uibutton

Hi I want to change the UIButton background color which user Tap on the button.

Composer not showing updated php version

php neo4j composer-php

I am trying to get composer to install a script for me.