Use JavaScript to find a specific link

前端 未结 4 656
清歌不尽
清歌不尽 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:33

    Use Array.prototype.some to see if at least one element in document.links has the href you're looking for.

    var has_link = [].some.call(document.links, function(link) {
       return link.href === 'http://www.youtube.com/SPECIFICURL';
    });
    

    You can patch it in old browsers using the patch found at MDN Array#some

提交回复
热议问题