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


基础教程推荐
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01