<iframe class="web" ID="mywebEdit" MARGINHEIGHT="5" MARGINWIDTH="5" width="100%" height="200"> </iframe><script type="text/javascript">
/*<![CDATA[*/fInitEditor(document.getElementById("mywebEdit"))
fCloseEditor(document.getElementById("mywebEdit"))function fInitEditor(XIframe)
{/* shawl.qiu code, void return */
XIframe.contentWindow.document.designMode="on";
XIframe.contentWindow.document.contentEditable=true;
XIframe.contentWindow.document.open();
}/*end function fInitEditor(XIframe)*/function fCloseEditor(XIframe)
{/* shawl.qiu code */
XIframe.contentWindow.document.close();
}/* function fCloseEditor(XIframe) */
/*]]>*/
</script>
/*<![CDATA[*/fInitEditor(document.getElementById("mywebEdit"))
fCloseEditor(document.getElementById("mywebEdit"))function fInitEditor(XIframe)
{/* shawl.qiu code, void return */
XIframe.contentWindow.document.designMode="on";
XIframe.contentWindow.document.contentEditable=true;
XIframe.contentWindow.document.open();
}/*end function fInitEditor(XIframe)*/function fCloseEditor(XIframe)
{/* shawl.qiu code */
XIframe.contentWindow.document.close();
}/* function fCloseEditor(XIframe) */
/*]]>*/
</script>
var editor;
editor=document.getElementById("mywebEdit").contentWindow;
editor.document.body.innerHTM = document.form1.content.value;
editor.document.designMode = 'On'
editor.document.contentEditable = true;
editor.document.open();
editor.document.close();
XIframe.contentWindow.document.designMode="on";
1.getElementById得到的是dom对象,应该用window.frames来获取窗口对象
2.函数不能立即执行,浏览器需要些时间来根据html初始化一个iframe,一般需要延时
<!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>
</head>
<body>
<iframe id="edit" name="edit" src="" width="200" height="200" frameborder="1"></iframe>
<script>
function $(strId){return document.getElementById(strId);}
function enableEdit(){
window.frames["edit"].document.designMode="On";
}
//给浏览器一些时间让他初始化一个窗口对象
setTimeout("enableEdit()",500);
</script>
</body>
</html>
也可以,估计就是没有延时造成的,还有你的代码中的那个innerHTM的拼写错误
改document.getElementById("mywebEdit").contentWindow.document.body.innerHTML= document.form1.content.value;