title: How to set HTML content into an iframe
body: <p>I have a HTML string </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;html&gt;
    &lt;body&gt;Hello world&lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>and I want to set it to an iframe with JavaScript. I am trying to set the HTML like this: </p>
  
  <pre class="lang-js prettyprint-override"><code>contentWindow.document.body.innerHTML
  </code></pre>
  
  <p>or</p>
  
  <pre class="lang-js prettyprint-override"><code>contentDocument.body.innerHTML
  </code></pre>
  
  <p>or</p>
  
  <pre class="lang-js prettyprint-override"><code>document.body.innerHTML
  </code></pre>
  
  <p>but IE gives "Access is denied." or "Object does not support this property or method." or "Invalid final element to the action." errors.</p>
  
  <p>Here is my full code:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;script type="text/javascript" src="jquery_1.7.0.min.js"/&gt;
      &lt;script type="text/javascript"&gt;
        $(document).ready(function(){
          var htmlString = "&lt;html&gt;&lt;body&gt;Hello world&lt;/body&gt;&lt;/html&gt;";
          var myIFrame = document.getElementById('iframe1');
          // open needed line commentary
          //myIFrame.contentWindow.document.body.innerHTML = htmlString;
          //myIFrame.contentDocument.body.innerHTML = htmlString;
          //myIFrame.document.body.innerHTML = htmlString;
          //myIFrame.contentWindow.document.documentElement.innerHTML = htmlString;
        });
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;p&gt;This is iframe:
        &lt;br&gt;
        &lt;iframe id="iframe1"&gt;
        &lt;p&gt;Your browser does not support iframes.&lt;/p&gt;
        &lt;/iframe&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>