function EnableEdit()
{
var editor;
editor = document.getElementById("HtmlEdit").contentWindow;
// 针对IE浏览器, make it editable
editor.document.designMode = 'On';
editor.document.contentEditable = true;
// For compatible with FireFox, it should open and write something to make it work
editor.document.open();
editor.document.writeln('<html><head>');
editor.document.writeln('<style>body {background: white;font-size:9pt;margin: 2px; padding: 0px;}</style>');
editor.document.writeln('</head><body></body></html>');
editor.document.close();
} <iframe ID="HtmlEdit" MARGINHEIGHT="1" MARGINWIDTH="1" width="100%" height="312">
</iframe>
<iframe src="" name="editor" id="editor" style="border: 1px solid rgb(204, 204, 204);" frameborder="0" height="200" width="400"></iframe>

<div>
<input type="button" onclick="insert(1)" value="insert image">
<input type="button" onclick="insert(2)" value="insert text">
</div> <script>
_win=$('#editor')[0].contentWindow; // 我们用 _win 变量代替 iframe window
_doc=_win.document; // 用 _doc 变量代替 iframe的document
_doc.designMode = 'On'; if( $.browser.msie ){
_doc.write('<img src="pet_store_api.png">');
}else{
_doc.open();
_doc.write('<img src="pet_store_api.png">');
_doc.close();
} function insertHTML( sHtml )
{
_win.focus();
if( $.browser.msie ){
_doc.selection.createRange().pasteHTML( sHtml ) ;
}else{
_doc.execCommand( 'InsertHtml' , '' , sHtml );
} }
function insert(type){
if(type==1){
insertHTML( '<img src="pet_store_api.png">' );
}else{
insertHTML( 'haha' );
}
}
</script>

  

让iframe可编辑的更多相关文章

  1. JavaScript Iframe富文本编辑器中的光标定位

    最近在项目中碰到一个比较棘手的问题: 在iframe富文本编辑器中,有个工具栏,这个工具栏在iframe标签之外,工具栏上有一个按钮,点击该按钮向iframe正在编辑中的光标处插入一个图片,图片会插入 ...

  2. UEditor编辑器并不难

    1.背景:        其实学习UEditor本该在这之前就应该学习整合到自己的项目中的了,第一次接触UEditor是在暑假期间,当时做东西在师兄的代码中发现了这东西,心想:卧槽,竟然可以这样整合别 ...

  3. 浏览器兼容性之JavaScript篇

    近期公司职务变动,我大部分工作时间都在做web前端开发.工作性质主要是跟javascript和css(层叠样式表)打交道,而JavaScript兼容性一直是Web开发者的心病,当然我也不例外,虽然我大 ...

  4. jqgrid定义多选操作

    先定义:    var SelectRowIndx; 然后加入以下属性: multiselect: true, onSelectRow: function () { SelectRowIndx = G ...

  5. 【Bootstrap系列】详解Bootstrap-table

    本篇文章将与大家分享bootstrap-table插件,借助于它实现基本的增删改查,导入导出,分页,父子表等. 至于其他技术,如冻结表头,列排列,行拖动,列拖动等,会在后续文章中与大家分享. 一    ...

  6. ***解决UEditor编辑器无法插入第三方视频地址

    转:http://blog.csdn.net/qq_16241043/article/details/53894847 xssFilter导致插入视频异常,编辑器在切换源码的过程中过滤掉img的_ur ...

  7. 在ASP.NET MVC4中实现同页面增删改查,无弹出框02,增删改查界面设计

    在上一篇"在ASP.NET MVC4中实现同页面增删改查,无弹出框01,Repository的搭建"中,已经搭建好了Repository层,本篇就剩下增删改查的界面了......今 ...

  8. 百度编辑器UEditor不能插入音频视频的解决方法

    引用:https://my.oschina.net/u/379795/blog/787985 xssFilter导致插入视频异常,编辑器在切换源码的过程中过滤掉img的_url属性(用来存储视频url ...

  9. 【原创】【1】rich editor系列教程。前期准备,兼容

    [1]前期准备,兼容 索引目录:http://www.cnblogs.com/henryli/p/3439642.html rich editor的原理无非是启用iframe的编辑模式或者div的co ...

随机推荐

  1. python Snakes 库安装

    SNAKES : A A Flexible High-Level Petri Nets Library SNAKES是python一个可以用于Petri网的库 python2安装SNAKES库:  在 ...

  2. 服务器端 安装svn

    趁着这波比较闲的时候来划一波水,想起自己那都快生会的腾讯云服务器 到现在还不能通过版本控制系统上传文件,于是趁这波功夫在服务器上安装个svn来管理代码. 首先就简单的介绍一波 svn : 首先svn不 ...

  3. 54.Storm环境搭建

    集群环境搭建 关闭防火墙,修改/etc/hosts配置(3台机器的ip可以相互通信) 下载安装jdk7(1.6以上),配置JAVA_HOME, CLASSPATH 搭建Zookeeper集群(保证3台 ...

  4. 一元运算符 +,可用于将变量转换为数字;如果变量不能转换,它仍然会是一个数字,但值为 NaN (不是一个数字)

    一元运算符,可用于将变量转换为数字: var y = "5"; var x = + y; console.log(typeof y);//string 类型 console.log ...

  5. 【DB2】How to resolve SQL20249N the statement was not processed with error

    相关链接 https://vinaysdb2blog.blogspot.com/2017/11/how-to-resolve-sql20249n-statement-was-not-processed ...

  6. IIS web证书申请与安装

    数字证书一般是由权威机构颁发的,操作系统会携带权威机构的根证书和中级证书.如果操作系统没有携带权威机构签发的根证书,浏览器会报警,如www.12306.cn,需要安装铁道部根证书后,才能正常访问. 证 ...

  7. EF基础知识小记一

    1.EF等ORM解决方案出现的原因 因为软件开发中分析和解决问题的方法已经接近成熟,然后关系型数据库却没有,很多年来,数据依然是保存在表行列这样的模式里,所以,在面相对象和高度标准化的数据库中产生了一 ...

  8. vue-devtools必备工具

    1.github下载地址:https://github.com/vuejs/vue-devtools 2.下载安成之后打开cmd进入vue-devtools文件夹把依赖装好npm install 之后 ...

  9. Vue中子组件调用父组件的方法

    Vue中子组件调用父组件的方法 相关Html: <!DOCTYPE html> <html lang="en"> <head> <meta ...

  10. CharacterRangeTable

    转载:https://github.com/jacoco/jacoco/wiki/CharacterRangeTable This page discusses a not yet available ...