So, I'm trying to find an answer to why this problem is happening; I've fixed the problem, but I want to know why it happened.
Google-provided conversion tracking code that injected an iframe using
document.write suddenly caused the page to cease to execute in all versions of Internet Explorer, but was remedied by injecting the same iframe using a non-
The snippet they give looks like this:
var axel = Math.random()+"";
var a = axel * 10000000000000;
document.write('<IFRAME SRC="https://fls.doubleclick.net/activityi;src=143;type=donat01;cat=indir4;ord=1;num='+ a + '?" WIDTH=10 HEIGHT=10 FRAMEBORDER=0></IFRAME>');
WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>
Now, I know that, for all sorts of reasons, document.write is hazardous and should be avoided. But, Google is giving me this code, so, I figured I could trust it.
It suddenly started breaking all of our pages for all users using Internet Explorer. As in, the page would stop rendering entirely once it hit the
As triage, I quickly substituted in the same code using the injection technique found in Google Analytics:
var iframe = document.createElement('iframe');
iframe.src = //the URL;
iframe.width = 0;
iframe.height = 0;
iframe.frameborder = 0;
var ref = document.getElementsByTagName('script');
This resolved the problem, without actually explaining:
Why does a nearly empty iframe, injected using document.write, break Internet Explorer, but this method above doesn't?
I've solved the problem; it turns out that it had nothing to do with the contents of the
It turns out the page is served by a framework that began using a backend DOM parser that, for reasons likely related to the presence of
</ within a
<script> tag within the
document.write, completely removes the
</iframe> tag from the generated page, even though it preserves it in the backend. (It's probably trying to enforce ETAGO rules).
The reason I was able to reproduce it was because I was copying the generated
document.write code, not the original code, and never noticed the missing
</iframe>. (And my "functioning" document.write code didn't have the stripped out
</iframe> tag, leading me to believe that the problem was the contents of the
As a result, browsers parsed an unclosed
<iframe> tag on the page, which Internet Explorer didn't know how to handle, and died part way through the parsing of the iframe (I'm still not totally sure why).