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

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

问题描述

我正在创建一个浏览器HTML编辑器。



我的设置是一个iframe,它包含正在编辑页面的视图和一个textarea纯文本HTML位于用户编辑的位置。



我试图将编辑后的HTML从textarea插入iframe,显示它们呈现HTML。



这可能吗?我已经尝试了以下内容:

HTML设置:

 < iframe id =render> 

< / iframe>

< textarea id =code>
HTML将是

这里
< / textarea>
< input type =submitid =edit_buttonvalue =Edit/>

JQuery设置:

  $('#edit_button')。click(function(){
var code = editor.getCode(); // editor.getCode()是一个codemirror函数,它从文本区
var iframe = $('#render');
iframe.html(code)
})

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



干杯



Eef

解决方案



document.designMode a>



属性,然后尝试添加HMTL

阅读



Mozilla中的富文本编辑



也是

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

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.

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 setup:

<iframe id="render">

</iframe>

<textarea id="code">
HTML WILL BE 

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

JQuery Setup:

$('#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)
})

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?

Cheers

Eef

解决方案

Set the

document.designMode

property and then try adding the HMTL

Read

Rich-Text Editing in Mozilla

also

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

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