How to replace entire contents of iframe?
<p><a href="http://stackoverflow.com/questions/5784638/replace-entire-content-of-iframe">This question</a> didn't receive any satisfactory answers, so I'm asking again.</p>

<p>I can get my iframe like this:</p>

<pre><code>var iframe = document.getElementById('preview');
var win = iframe.contentWindow;
var doc = win.document;
</code></pre>

<p>And write some initial HTML to it like this:</p>

<pre><code>doc.write('&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;link rel="stylesheet" type="text/css" href="reset.css"&gt;&lt;/head&gt;&lt;body&gt;blah blah&lt;/body&gt;&lt;/html&gt;');
</code></pre>

<p>And that works great, but now I want to replace the entire thing with some new content. How can I do that?</p>

<p>To be clear, by "entire thing" I mean the <code>&lt;head&gt;</code> too. I need to link some external JS and CSS there.</p>

<p>Preferably, this would also include the <code>&lt;!DOCTYPE&gt;</code>, but it's non-essential at this point.</p>
