所以我有一个 iframe,它应该在按下按钮后保存来自文本区域的呈现代码,但我不确定如何在 javascript 或 jquery 中执行此操作。我知道如何发送带有 URL 的特定站点以在网页内显示,但出于某种原因,当我尝试呈现文本区域并将其发送到 iframe 时,它不起作用。
这是我的 iframe:
<iframe id="outputIframe"></iframe>
这是我编写的用于从 textarea 编辑器发送内容的函数(这适用于 a 但不适用于 ):
function openIframe() {
var e = document.getElementById('outputIframe');
var editorHTML = editor.getValue();
e.document.innerHTML = editorHTML;
}
因此编辑器 (codemirror) 保存用户编写的 HTML 代码,然后当用户按下按钮时它应该输出到 'outputIframe' iframe 元素中。这类似于 w3schools 的“试用”部分。
最佳答案
function openIframe() {
var editorHTML = editor.getValue();
var iframe = document.getElementById('outputIframe');
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(editorHTML);
iframe.contentWindow.document.close();
}
关于javascript - 如何将网页从文本区域发送到 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28598223/