<!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: 天堂左我往右