<script>
function insert_pic(value,picid){
    value = "http://image2.sina.com.cn/ent/s/m/p/2007-04-26/U1326P28T3D1534001F358DT20070426114835.jpg";
    var  fff = testframe.document.getElementById('testtd');
    fff.focus();
    var range = fff.document.selection.createRange();
    var ToAdd = '';
    ToAdd += "<img src='"+value+"' title='点击查看更多大图' border=0>";          
    ToAdd += "<br><br>";
    range.pasteHTML(ToAdd);
    fff.focus();
}
</script><INPUT TYPE="button" value="fff" onclick="insert_pic()">
<table>
    <tr>
       <td>
       <iframe name="testframe" id="testframe" src="test.html"></iframe>
       </td>
    </tr>
</table>test.html内容
<table>
<tr><td id="testtd" name="testtd"></td></tr>
</table>使用js  insert_pic 函数 在test.html的testtd里面插入一张图片
以上代码在ie下测试正常,在firfox里面不行
请高手解答

解决方案 »

  1.   

    http://www.nextway.cn/article.asp?id=248
      

  2.   

    首先感谢你提供的方法
    对您提供的方法,进行了测试
    <html>
    <head></head>
    <body>
    <INPUT TYPE="button" value="点击插入内容" onclick="insertHTML()"><BR>
    <IFRAME id='HtmlEdit' style="WIDTH: 100%; HEIGHT: 296px" marginWidth='0' marginHeight='0'></IFRAME>
    <script language="javascript">
         var editor;
         editor = document.getElementById("HtmlEdit").contentWindow;
         
         //只需键入以下设定,iframe立刻变成编辑器。
         editor.document.designMode = 'On';
         editor.document.contentEditable = true;
         
         //但是IE与FireFox有点不同,为了兼容FireFox,所以必须创建一个新的document。
         editor.document.open();
         editor.document.writeln('<html><body></body></html>');
         editor.document.close();     function insertHTML(html)
         {
             html = "插入的内容";
             //alert(html);
             if (editor.document.selection.type.toLowerCase() != "none")
             {
             editor.document.selection.clear() ;
             }
             editor.document.selection.createRange().pasteHTML(html) ; 
         }  </script>
    </body>
    </html>在ie里面是没有问题,在firfox里面还是不能 插入内容我提问的里面 还有就是赋值的是iframe 里面的一个对象