可编辑 iframe, removeChild时, 非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>

<script>
function f1(){
document.body.removeChild(do01);
}
function f2(){
document.body.appendChild(do01);

// 第一种方法
meifr01.contentWindow.document.designMode="On";
meifr01.contentWindow.document.open();
meifr01.contentWindow.document.write('<html><head><style>html,body{margin:5px;font:12px/1.231 arial;cursor:text;}</style></head><body id="easyrt_body"></body></html>');
meifr01.contentWindow.document.close();

// 第二种方法,估计得iframe load之后
// setTimeout(f3,0);

}
function f3(){
meifr01.contentWindow.document.designMode="On";
}

//http://www.v-ec.com/dh20156/code/easyrt/easyrt.html
</script>
</head>


<body onload=init()>
这个bug是这样的,我们常常会用iframe做html编辑器,当iframe离开文档以后,再append进来,这个时候,非IE浏览器下iframe会变成不可编辑的,并且内容全部丢失,
不可编辑这个问题需要重新设置一下iframe,内容丢失就没办法了...
<div id="d001"><iframe id="ifr1"></iframe></div>
<input type="button" value="none" onclick="f1()" />
<input type="button" value="display" onclick="f2()" />
<input type="button" value="edt" onclick="f3()" />
</body>

</html>

<script>
function init(){
window.do01 = document.getElementById("d001");
window.meifr01 = document.getElementById("ifr1");
meifr01.contentWindow.document.designMode="On";
}
</script>





补充,在非IE下,重新appendChild一下iframe, win和doc都变了, iframe的unload事件也会被触发

by: 天堂左我往右
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值