FF下JS动态生成iframe编辑器,编辑状态无法启动,IE下正常,求高手解答,太奇葩了<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="css/stylel.css"/>
<script>
var getTextareaByClass=function(classname){
var ifms=document.getElementsByTagName("textarea");
for(var i=0;i<ifms.length;i++){
if(ifms[i].className.indexOf(classname)>-1){
return ifms[i];
}
}
return null;
}
var extendJson=function(destination,source){
for(var json in source){
destination[json] = source[json];
}
return destination;
}var teditor=function(options){
_this = this;
_this._init(options);
_this._exec();
}
teditor.prototype={
_init:function(options){
_this.ieRange=false;
_this.options={
editor:getTextareaByClass("tEditor"),
width:0,
height:0
};
_this.options = extendJson(_this.options,options);
_this._createHTML();
},
_createHTML:function(){ //生成iframe,插入到textarea前面
var table=document.createElement("table");
table.cellSpacing = "0";
table.cellPadding = "0";
table.border = "0";
var tagsRow = table.insertRow(0);
var tagsCell = tagsRow.insertCell(0);
var iframeRow = table.insertRow(1);
var iframeCell = iframeRow.insertCell(0);
_this.editor = document.createElement("iframe");
_this.editor.style.width = !!_this.options.width ? _this.options.width : _this.options.editor.style.width;
_this.editor.style.height = !!_this.options.height ? _this.options.height : _this.options.editor.style.height;
iframeCell.appendChild(_this.editor);
_this.options.editor.parentNode.insertBefore(table,_this.options.editor);
},
_exec:function(){
//alert("1"); //如果在这alert延迟下后面的代码就能正常开启编辑模式
_this.win=_this.editor.contentWindow;
_this.doc=_this.win.document;
_this.doc.designMode='On';//可编辑
_this.win.focus();
}
}
window.onload=function(){
var editor=new teditor();
};
</script>
</head><body>
<textarea id="tEditor" name="tEditor" class="tEditor" style="width:600px; height:200px;"></textarea>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="css/stylel.css"/>
<script>
var getTextareaByClass=function(classname){
var ifms=document.getElementsByTagName("textarea");
for(var i=0;i<ifms.length;i++){
if(ifms[i].className.indexOf(classname)>-1){
return ifms[i];
}
}
return null;
}
var extendJson=function(destination,source){
for(var json in source){
destination[json] = source[json];
}
return destination;
}var teditor=function(options){
_this = this;
_this._init(options);
_this._exec();
}
teditor.prototype={
_init:function(options){
_this.ieRange=false;
_this.options={
editor:getTextareaByClass("tEditor"),
width:0,
height:0
};
_this.options = extendJson(_this.options,options);
_this._createHTML();
},
_createHTML:function(){ //生成iframe,插入到textarea前面
var table=document.createElement("table");
table.cellSpacing = "0";
table.cellPadding = "0";
table.border = "0";
var tagsRow = table.insertRow(0);
var tagsCell = tagsRow.insertCell(0);
var iframeRow = table.insertRow(1);
var iframeCell = iframeRow.insertCell(0);
_this.editor = document.createElement("iframe");
_this.editor.style.width = !!_this.options.width ? _this.options.width : _this.options.editor.style.width;
_this.editor.style.height = !!_this.options.height ? _this.options.height : _this.options.editor.style.height;
iframeCell.appendChild(_this.editor);
_this.options.editor.parentNode.insertBefore(table,_this.options.editor);
},
_exec:function(){
//alert("1"); //如果在这alert延迟下后面的代码就能正常开启编辑模式
_this.win=_this.editor.contentWindow;
_this.doc=_this.win.document;
_this.doc.designMode='On';//可编辑
_this.win.focus();
}
}
window.onload=function(){
var editor=new teditor();
};
</script>
</head><body>
<textarea id="tEditor" name="tEditor" class="tEditor" style="width:600px; height:200px;"></textarea>
</body>
</html>
解决方案 »
- ExtJs代码详细解释
- 如何制作这个Js广告
- JSP 网页中如何去掉radio每个选项前的那个小圆圈
- onblur 第2次时无反应
- 这个页面查看源码时,居然获取不到真正的HTML CODE,请教大家
- html中的js如DelKeyword('32016407','18732233');,他的数字是随机的吗?
- select标签可否读取已选取值,显示当前状态?
- 请问:把javascript代码组织成一个js文件和把其直接嵌入到html页面中有那些区别?
- 如何打开新的窗口,关闭原来的窗口?
- 弹出对话框用什么插件比较好?
- JS操作cookies,求完美方法
- |zyciis|如何在form submit 时通过js添加他的post数据如 name=jerry&pass=123456 谢谢
_this.doc.open();
_this.doc.writeln('<html><body></body></html>');
_this.doc.close();
虽然不知道原理