user1338543
user1338543

Reputation: 1

Change the whole content of iFrame

I have a textarea in which I wan't to add HTML code that will compose a full webpage, and as I type this content will be rendered in an iframe

For example in the textarea I'll write the following code:

<!DOCTYPE html>
<html>
    <head>
        <title>Live generate</title>
        <style></style>
    </head>
    <body>
    </body>
</html>

My problem is that I don't know how to access the iFrame in order to change it's full content so that it matches the one above

Upvotes: 0

Views: 248

Answers (1)

Daniel van Dommele
Daniel van Dommele

Reputation: 550

you should be able to get the iframe by its id with document.getElementsById or through jquery and then get its document, open it and write to it.

Like:

var iframe = $("iframe"); // or by Id $("#myIframeId")
var doc = iframe.document;

doc.open();
doc.write($("#myTextArea").text());
doc.close();

Upvotes: 2

Related Questions