title: "Manual" page refresh in JavaScript through AJAX
body: <p>I want to simulate a page change (e.g. user clicking on a link) using JavaScript. Meaning I load the source of the new page through AJAX and then replace things in the DOM manually. Something like this:</p>
  <pre><code>$.get(linkTarget, function(html) {
    var bodyHtml = /&lt;body.*?&gt;([\s\S]*)&lt;\/body&gt;/.exec(html)[1];
    if (bodyHtml) {
      $('body &gt; *:not(.thingsToKeep)').remove();
      $(&quot;body&quot;).prepend(bodyHtml);
    }
  });
  </code></pre>
  <p>Problems will arise though when there is a lot of JavaScript on the page which will then basically be executed once on top of itself with variables and constants already declared. Pretty sure this will break many scripts if done naively.</p>
  <p>And the point of the whole exercise is to be able to keep some of the contents of the existing page running (say, a playing video) while reloading everything else.</p>
  <p>So the question is, is this idea (reloading a page &quot;manually&quot;) a &quot;known science&quot;? Any library that does this?</p>