Note that there are some explanatory texts on larger screens.

plurals
  1. POOpen a new browser window/iframe and create new document from HTML in TEXTAREA?
    primarykey
    data
    text
    <p>I'm trying to write a web application using the new offline capabilities of HTML5. In this application, I'd like to be able to edit some HTML&#8212;a full document, not a fragment&#8212;in a <code>&lt;textarea&gt;</code>, press a button and then populate a new browser window (or <code>&lt;iframe&gt;</code>, haven't decided yet) with the HTML found in the <code>&lt;textarea&gt;</code>. The new content is not persisted anywhere except the local client, so setting the source on the <code>window.open</code> call or the <code>src</code> attribute on an <code>&lt;iframe&gt;</code> is not going to work.</p> <p>I found the following question on StackOverflow: "<a href="https://stackoverflow.com/questions/1439903/putting-html-from-the-current-page-into-a-new-window">Putting HTML from the current page into a new window</a>", which got me part of the way there. It seems this technique works well with fragments, but I was unsuccessful in getting an entirely new HTML document loaded. The strange thing is when I view the DOM in Firebug, I see the new HTML&#8212;it just doesn't render.</p> <p>Is it possible to render a generated HTML document in a new window or <code>&lt;iframe&gt;</code>?</p> <p><strong>EDIT</strong>: Here's a "working" example of how I'm attempting to accomplish this:</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Test new DOM&lt;/title&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt; function runonload() { return $("#newcode")[0].value; } $(function() { $("#runit").click(function() { w=window.open(""); $(w.document).ready(function() { $(w.document).html(w.opener.runonload()); }); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;textarea id="newcode"&gt; &amp;lt;!doctype html&amp;gt; &amp;lt;html&amp;gt; &amp;lt;head&amp;gt; &amp;lt;title&amp;gt;New Page Test&amp;lt;/title&amp;gt; &amp;lt;/head&amp;gt; &amp;lt;body&amp;gt; &amp;lt;h1&amp;gt;Testing 1 2 3&amp;lt;/h1&amp;gt; &amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt; &lt;/textarea&gt; &lt;br/&gt; &lt;button id="runit"&gt;Run it!&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload