title: Replacing entire contents of iframe (including doctype & html tags) with jQuery
body: <p>There are quite a few other posts on stackoverflow that ask nearly the same question, but in all the answers I've read so far, they don't address how to essentially replace the entire document of the iframe, including the DOCTYPE and html tags. </p>
  
  <p>I am retrieving the HTML for an entire page via a jQuery.ajax request and attempting to use the returned HTML as the new HTML of the iframe. Here's an example of the HTML being returned from the ajax request:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en-US"&gt;
      &lt;head&gt;
          &lt;link rel="stylesheet" type="text/css" media="all" href="main.css"&gt;
          &lt;title&gt;Test Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Heading&lt;/h1&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I then inject this HTML into the iframe via:</p>
  
  <pre><code>$('#my-iframe').contents().find('html').html(returnedHtml);
  </code></pre>
  
  <p>As suggested on most of the other posts on this subject. However, when I inspect the contents of the iframe, the document is structured as follows:</p>
  
  <pre><code>&lt;html&gt;
      &lt;link rel="stylesheet" type="text/css" media="all" href="main.css"&gt;
      &lt;title&gt;Test Page&lt;/title&gt;
      &lt;h1&gt;Heading&lt;/h1&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Notice the lack of DOCTYPE, missing lang attribute on the html tag, missing head and body tags.</p>
  
  <p>Any suggestions? (Note that just changing the iframe's src attribute to the necessary url is not possible in this app due to various factors)</p>