将 HTML 插入 iframe [英] Insert HTML into iframe

查看:57
本文介绍了将 HTML 插入 iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个在浏览器中的 HTML 编辑器.我正在使用名为 Code Mirror 的语法荧光笔,非常好.

I am creating a in browser HTML editor. I am using the syntax highlighter called Code Mirror which is very good.

我的设置是一个 iframe,其中包含正在编辑的页面的视图和一个文本区域,用户编辑的纯文本 HTML 所在的文本区域.

My setup is an iframe that holds a view of the page which is being edited and a textarea which the plain text HTML sits which the user edits.

我正在尝试将已编辑的 HTML 从 textarea 插入到显示它们呈现的 HTML 的 iframe 中.

I am trying to insert the edited HTML from the textarea into the iframe which displays they rendered HTML.

这可能吗?我尝试了以下方法:

Is this possible? I have tried the following:

HTML 设置:

<iframe id="render">

</iframe>

<textarea id="code">
HTML WILL BE 

HERE
</textarea>
<input type="submit" id="edit_button" value="Edit" />

jQuery 设置:

$('#edit_button').click(function(){
    var code = editor.getCode(); // editor.getCode() is a codemirror function which gets the HTML from the text area
    var iframe = $('#render');
    iframe.html(code)
})

这似乎不会将 HTML 加载到 iframe 中,是否有将 HTML 插入 iframe 的特殊方法或者这不可能?

This does not seem to load the HTML into the iframe, is there a special method to insert HTML into a iframe or is this not possible?

推荐答案

设置文档.designMode 属性,然后尝试添加 HTML.

Set the document.designMode property and then try adding the HTML.

另请参阅:Mozilla 中的富文本编辑

这篇关于将 HTML 插入 iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆