title: Creating an iframe with given HTML dynamically
body: <p>I'm trying to create an iframe from JavaScript and fill it with arbitrary HTML, like so:</p>
  
  <pre><code>var html = '&lt;body&gt;Foo&lt;/body&gt;';
  var iframe = document.createElement('iframe');
  iframe.src = 'data:text/html;charset=utf-8,' + encodeURI(html);
  </code></pre>
  
  <p>I would expect <code>iframe</code> to then contain a valid window and document. However, this isn't the case:</p>
  
  <blockquote>
    <p>> console.log(iframe.contentWindow);<br>
    null</p>
  </blockquote>
  
  <p>Try it for yourself: <a href="http://jsfiddle.net/TrevorBurnham/9k9Pe/">http://jsfiddle.net/TrevorBurnham/9k9Pe/</a></p>
  
  <p>What am I overlooking?</p>