javascript - 更改 iFrame 的全部内容

标签 javascript jquery html iframe

我有一个文本区域,我不想在其中添加组成完整网页的 HTML 代码,当我键入时,此内容将在 iframe 中呈现

例如,在文本区域中我将编写以下代码:

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

我的问题是我不知道如何访问 iFrame 来更改其完整内容,使其与上面的内容匹配

最佳答案

您应该能够通过 document.getElementById 的 id 或通过 jquery 获取 iframe,然后获取其文档,打开它并写入内容。

喜欢:

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

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

关于javascript - 更改 iFrame 的全部内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10190118/

相关文章:

javascript - 将 JSON HTTP POST 请求转换为 Java 对象时出错

jquery - 如何为html内容中的不同 block 运行相同的jquery代码?

javascript - IE 9 兼容 View 导致脚本无法加载

javascript - jquery,删除动态添加的内容

javascript - 获取除破折号之外的所有内容 - javascript 中的正则表达式

javascript - 如何在驼峰式键名之间添加空格?

javascript - 递归触发错误 "Maximum call stack size exceeded error"

javascript - 将 jquery 对象转换为函数内的常规 js

html - CSS 溢出 : Force one div to overflow

div 周围的 CSS 边框大于页面宽度