How to select anchor tag href value in external link jquery?

时间:2016-07-15 08:38:36

标签: jquery html5

This is my code to create an external link(http:www.vv.com) for the selected text. Again select another text and create an external link (http:www.aa.com) for that text.

  1. Now am select the both External link. Only show the first External link ('href'= http://www.vv.com)href值切换切换操作。
  2. 现在选择一个外部链接。仅显示外部链接href值。

    <body> 
    <h1>Create a link</h1> 
    Select some text and click the button. The selected text will become the named hyperlink<br>
    My Homepage<br>
    My Favorite<br>
    My Search Page<br><br>
    <button onclick="createLink(event)">Make it a link</button> 
    <script>
    function createLink(e){//b.b. Troy III p.a.e.
     if(e.target){ //get ATL
         var range = window.getSelection().getRangeAt(0);
         var selects = browser.find_elements_by_tag_name("a");
         alert(selects);
    
        var b = range.toString();  
        alert(b);
        var z = document.createElement("a");
        var l2 = prompt("Enter URL:", "http://");
        if (l2 == null) return;
            b = b.link(l2);
            z.innerHTML=b;
            range.deleteContents();
            range.insertNode(z)
            }
     else{ //get the ATW
            document.execCommand("CreateLink") 
    }
    }
    </script>
    </body>
    

1 个答案:

答案 0 :(得分:0)

$('a[href^="http://example.com/external/link"]').click(function() {
      _gaq.push(['_trackPageview', '/external/pagename']);
});

source

相关问题