title: HTML file that loads another HTML via AJAX and then replaces itself
body: <p>I want to have a simple HTML file act as a bootstrap for a second HTML file (which will be loaded using AJAX, then processed with javascript), which would replace the first entirely.</p>
  
  <h3>bootstrap.htm</h3>
  
  <ol>
  <li>loads content.htm using AJAX (jQuery fine for this job)</li>
  <li>modifies content using javascript (various custom filters/modifications required)</li>
  <li>replaces itself with newly modified content</li>
  </ol>
  
  <p>I expect it might not be 100% possible, as replacing the doctype might be hard, but I expect it is not too hard to replace all the body content, and all the head content (maybe just all the content of HTML?)</p>
  
  <p>Does anyone have any advice on how to go about this?</p>
  
  <h2>EDIT: I tried to directly do what I really want...</h2>
  
  <pre><code>$.get("content.htm", function(d) {
    console.log(d);
    return $(document).html(d);
  </code></pre>
  
  <p>But this does not work, and leaves me with an empty document
      });</p>
  
  <h2>EDIT: Best solution so far (still conceptual)</h2>
  
  <ul>
  <li><code>bootstrap.htm</code> loads, and is very careful only to create one global variable (lets say<code>bs</code>)</li>
  <li><code>bootstrap.htm</code> then loads the <code>content.htm</code> file, and processes it further</li>
  <li><code>bootstrap.htm</code> replaces the <code>html</code> tag content with the contents of the processed <code>content.htm</code>'s <code>html</code> tag</li>
  <li><code>bootstrap.htm</code> then searches the new content, and executes any inline javascript, being careful not to execute code that has already been executed</li>
  <li><code>bootstrap.htm</code> removes it's global variable (although there is little point at this stage, when most of the imported code has already been run)</li>
  </ul>
  
  <p>This still does not allow the DOCTYPE to be changed, and the executing of imported code seems a bit unreliable, but this is the best idea I have so far.</p>