<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>

解决方案 »

  1.   

    我大致改了一下,看看行不行?
     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();  
      

  2.   

    很奇怪好像不支持这个写法
    XIframe.contentWindow.document.designMode="on"; 
      

  3.   

    可能有两个地方有问题
    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>
      

  4.   

    实验了下用document.getElementById(<id>).contentWindow.document.designMode="On";
    也可以,估计就是没有延时造成的,还有你的代码中的那个innerHTM的拼写错误
      

  5.   

    我看了一下,好像是document.getElementById("mywebEdit").contentWindow.document.body.innerHTM = document.form1.content.value; 这句有问题,
    改document.getElementById("mywebEdit").contentWindow.document.body.innerHTML= document.form1.content.value; 
      

  6.   

    改成document.getElementById("mywebEdit").contentWindow.document.body.innerHTML= document.form1.content.value; 确实是可以输入文本了,但是好像编辑器上面的那些功能还是用不了。譬如插入图片,加粗,下划线等等,都不可以。多谢各位了。