Darth Coder
Darth Coder

Reputation: 1798

How to get all outbound links on current web page from Chrome extension

I am working on a code wherein I need to scan and get a list of all outbound links from the web page open in the current active tab. This has to be achieved by simply clicking my extension. I am looking to write this code in javascript, but so far have not been able to find anywhere to start. Can someone please point me in the right direction and help me with this code? Thanks in advance.

Upvotes: 0

Views: 3441

Answers (1)

Ofir Israel
Ofir Israel

Reputation: 3913

Check this out: Get all href links in DOM

Basically they use the following code to create an array of the links of the page:

var array = [];
var links = document.links;
for(var i=0; i<links.length; i++) {
  array.push(links[i].href);
}

For creating the chrome extension try reading: http://coryg89.github.io/technical/2013/08/13/how-to-create-your-own-chrome-extensions/ , which is a good guide to do so.

This looks like what you need. Good luck!

Upvotes: 1

Related Questions