title: Why does this document.write iframe ads code completely break Internet Explorer?
body: <p>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.</p>
  
  <h2>TL;DR</h2>
  
  <p>Google-provided conversion tracking code that injected an iframe using <code>document.write</code> 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-<code>document.write</code> method.</p>
  
  <h2>The Story:</h2>
  
  <p>Doubleclick is an advertising network that provides a JavaScript snippet to track conversions from ads. </p>
  
  <p>The snippet they give looks like this:</p>
  
  <pre><code>&lt;SCRIPT language="JavaScript"&gt;
  var axel = Math.random()+"";
  var a = axel * 10000000000000;
  document.write('&lt;IFRAME SRC="https://fls.doubleclick.net/activityi;src=143;type=donat01;cat=indir4;ord=1;num='+ a + '?" WIDTH=10 HEIGHT=10 FRAMEBORDER=0&gt;&lt;/IFRAME&gt;');
  &lt;/SCRIPT&gt;
  &lt;NOSCRIPT&gt;
  &lt;IFRAME SRC="https://fls.doubleclick.net/activityi;src=143;type=donat01;cat=indir4;ord=1;num=1?"
  WIDTH=1 HEIGHT=1 FRAMEBORDER=0&gt;&lt;/IFRAME&gt;
  &lt;/NOSCRIPT&gt;
  </code></pre>
  
  <p>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. </p>
  
  <p>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 <code>document.write</code>. This was crazy: One of the largest third party advertisers on the internet had given me JavaScript that had LITERALLY broken my purchase pages for 25% of my traffic!</p>
  
  <p>As triage, I quickly substituted in the same code using the injection technique found in Google Analytics: </p>
  
  <pre><code>var iframe = document.createElement('iframe');
  iframe.src = //the URL;
  iframe.width = 0;
  iframe.height = 0;
  iframe.frameborder = 0;
  var ref = document.getElementsByTagName('script')[0];
  ref.parentNode.insertBefore(iframe, ref);
  </code></pre>
  
  <p>This resolved the problem, without actually explaining:</p>
  
  <h2>Why does a nearly empty iframe, injected using document.write, break Internet Explorer, but this method above doesn't?</h2>