Use JavaScript to find a specific link

前端 未结 4 658
清歌不尽
清歌不尽 2021-01-20 03:54

Could anyone help me with a function for JavaScript which searches the source code and compares all of the links on the site with the specific link I am looking for.

4条回答
  •  面向向阳花
    2021-01-20 04:19

    function find_link_by_href(address)
        links = document.getElementsByTagName("a");
    
        for(var i = 0; i < links.length; i++) { 
          if( links[i].href === address ) {
            console.log("Url found"); 
            return; 
         } 
     }
    

    You can call it like this:

    find_link_by_href("http://www.youtube.com/SPECIFICURL");
    

提交回复
热议问题