可編輯 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 οnlοad=init()>
這個bug是這樣的,我們常常會用iframe做html編輯器,當iframe離開文檔以後,再append進來,這個時候,非IE瀏覽器下iframe會變成不可編輯的,並且內容全部丟失,
不可編輯這個問題需要重新設置一下iframe,內容丟失就沒辦法了...
<div id="d001"><iframe id="ifr1"></iframe></div>
<input type="button" value="none" οnclick="f1()" />
<input type="button" value="display" οnclick="f2()" />
<input type="button" value="edt" οnclick="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: 天堂左我往右
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章