<Script Language="JavaScript">
      function addLink(){
        
         var oRange = document.selection.createRange();
         if(oRange.text!="")
         {
           var oUrl =prompt("链接网址...","http://www.163.com/");
            
            var oHtml = "<a href="+oUrl+" target=_blank>"+oRange.text+"<a>";
            
           oRange.pasteHTML(oHtml);
         }
         else
         {
           alert("您没有选择加链接的文字!");
         }
      }
</Script>
网易  新浪  搜狐<br><br>
<input type="button" value="添加链接" onclick="addLink();" ID=Button1>

解决方案 »

  1.   

    function addLink()
    {    
        if(IframeID.document.selection.type == 'None')    
        {
            window.alert('请选择设置链接的文字/图片!');
        }
        else if(IframeID.document.selection.type == 'Control') 
               
            {
                var oRange = IframeID.document.selection.createRange();
                var userurl = window.prompt('请输入链接网址...','http://'); 
                var oHtml;
                var imgurl = oRange.item(0).outerHTML.replace('<IMG','<IMG border=0'); 
                oHtml = '<a href='+userurl+' target=_blank>'+imgurl+'</a>';
                alert(oHtml);
                oRange.pasteHTML(oHtml);
            }       }以上代码:当IframeID.document.selection.type == 'Control'时,提示oRange.pasteHTML(oHtml);这句出错:"对像不支持此属性或方法",是怎么回事,为什么IframeID.document.selection.type == 'Text'时就没有这个问题?