Insert HTML into iframe(将 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 HTML 插入 iframe


- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06