Replacing all HTML code with a new one with scripts (via JS)
<p>Question is in title, I ask how to do that? I want after replacing all HTML code to be executed JS scripts, but my example below doesn't work.</p>

<p>Here is what I have tried:</p>

<pre><code>...     
&lt;script&gt;
document.getElementsByTagName('html')[0].innerHTML = "&lt;html&gt;" &amp; String.fromCharCode(13) &amp; "&lt;head&gt;" &amp; String.fromCharCode(13) &amp; "&lt;/head&gt;" &amp; String.fromCharCode(13) &amp; "&lt;body&gt;" &amp; String.fromCharCode(13) &amp; "&lt;/body&gt;" &amp; String.fromCharCode(13) &amp; "&lt;/html&gt;";
var text = 'document.write("&lt;h1&gt;TEST&lt;/h1&gt;&lt;scr"+"ipt&gt;alert(1);&lt;/scr"+"ipt&gt;");';
script = document.createElement('script');
script.appendChild(document.createTextNode(text));
document.body.appendChild(script);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Does anyone know solution for this problem? Thanks in advance!</p>

<hr>

<p>Sorry, I have corrected errors and here is what I have done:</p>

<pre><code>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;
// document.getElementsByTagName('head')[0].innerHTML = "";
document.getElementsByTagName('body')[0].innerHTML = ""; // This doesn't clear all in body :(
document.write("&lt;h1&gt;New text and script!&lt;/h1&gt;&lt;scr"+"ipt&gt;alert(1)&lt;/scr"+"ipt&gt;");
&lt;/script&gt;
&lt;h1&gt;I want to clear this text.&lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>All works but I don't know how to clear that text on end. :( Can someone tell me if there is a solution for this problem?</p>
