简体   繁体   English

更改iFrame的全部内容

[英]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 我有一个textarea,我不想添加组成完整网页的HTML代码,当我输入时,这个内容将在iframe中呈现

For example in the textarea I'll write the following code: 例如在textarea中,我将编写以下代码:

<!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 我的问题是,我不知道如何访问iFrame以更改其完整内容,以便与上面的内容相匹配

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. 你应该能够通过其id与document.getElementsById或通过jquery获取iframe,然后获取其文档,打开它并写入它。

Like: 喜欢:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM