自己做了一个在线编辑器,一直用得很好。我准备把在线编辑器用在论坛里面。
就用 IFRAME 套进去。结果在线编辑功能要不是不起作用,不然就总出错。    主程序是这样:
<div style="width: 850px; height: 280px; overflow:visible">
<iframe src="../../system/bbs/pubArticle/pubArt.htm?x=$htmlkey[3]&pub&" style="width: 800px; height: 450px" marginwidth="0" framespacing="0" marginheight="0" frameborder="0" ></iframe>
</div>   IFRAME 里面比如
//插水平线
function InsertHorizontalRule()
{
oEditor.document.execCommand("InsertHorizontalRule");
oEditor.focus();
}结果是插到 IFRAME 外面去了。
要文字加粗,先选中文字,一点加粗,失去选中,什么反应也没有。
但我单独运行 pubArt.htm ,什么问题都没有。
是不是 document.execCommand 对iframe 有特殊的讲究。谢谢高手指点。

解决方案 »

  1.   

    先oEditor.focus(); 
    再oEditor.document.execCommand("InsertHorizontalRule"); 
    试试看
      

  2.   

      谢谢。
       但按你说的,每次都插在最上面。加粗的语句是这样的。
    //加粗
    function bold(){
    var sText = oEditor.document.selection.createRange();
    if(sText!=""){
    oEditor.document.execCommand("bold");
    }
    }
    但一点鼠标,本来选中的文字一下就没选中了,文字也不变粗。
       
      

  3.   

    function bold(){
      oEditor.focus();
      var sText = oEditor.document.selection.createRange(); 
      if(sText!=""){ 
         oEditor.document.execCommand("bold"); 
      } 

    试试看