我查了一下 FF 下 window.getSelection 这个对象,但始终不知如何获取是 IMG ,TABLE ,请高手给出比较详细的代码

解决方案 »

  1.   

    这个在FF下可以,在IE下得不到,你综合一下吧..
    <html>
    <head></head>  
    <body onLoad="a()"> 
    <span onClick="a()">123</span>
       <table border="1" width="100%" id=edit >
       <tr>
       <td width="100%">
       
       <IFRAME id="editor" name="editor"  src="about:blank"></IFRAME>
       
       </td>
       </tr>
     </table>
    <script language="javascript">function showContextMenu(oEvent)
    {
    if(document.all){
    var editor = window.frames["editor"];
    alert(window.event);
    }else{
    alert(oEvent.target.tagName);
    }
        return false;
    }function a(){
       var editor = window.frames["editor"];
       editor.document.designMode="on"
       editor.focus();
       editor.document.contentEditable = true; 
       editor.document.write("<a href='#'>test</a><table ><tr><td>table</td></tr></table><img src=''/>");
       editor.document.close();
       
       if(document.all){
       editor.document.attachEvent("oncontextmenu", function(){return showContextMenu();});
       }else{
       editor.document.addEventListener("contextmenu", function(oEvent){ oEvent.preventDefault(); return showContextMenu(oEvent);}, false);
       }
    }
    </script>
    </body>
    </html>