在一段文本编辑器里面
用this.editorDoc.execCommand('createLink', true, true);给文本加上链接,但是怎么能让链接重新打开一个页面而不是覆盖本页面呢,谢谢大家
123

解决方案 »

  1.   

    在a标签中添加属性target="_blank";
    具体方法LZ请看这个帖子http://bbs.51js.com/viewthread.php?tid=10973
      

  2.   

    给楼主一个完整的例子:
    <HTML>
    <BODY>
    <H1 unselectable="on">Creating a Link and Retrieving the URL</H1>
    <script>
    function AddLink()
    {//Identify selected text
    var sText = document.selection.createRange();
    if (!sText==""){
    //Create link
    document.execCommand("CreateLink");
    //Replace text with URL
    if (sText.parentElement().tagName == "A"){
    sText.parentElement().target = "_blank"; 
    document.execCommand("ForeColor","false","#FF0033");
    }
    }
    else{
    alert("Please select some blue text!");
    }
    }
    </script>
    <P unselectable="on">Select any portion of the following blue text, such as "My favorite Web site". Click the button to turn the selected text into a link. The text will be changed to the URL that you specify.</P>
    <P style="color=#3366CC">My favorite Web site is worth clicking on. Don't forget to check out my favorite music group!</P>
    <BUTTON onclick="AddLink()" unselectable="on">Click to add link</BUTTON>
    </BODY>
    </HTML>