This question already has an answer here:
can anybody tell me a way to get all the href attributes(links) in a web site using javascript?if you could give me a code example, i will be most thankful.
This question already has an answer here:
can anybody tell me a way to get all the href attributes(links) in a web site using javascript?if you could give me a code example, i will be most thankful.
One simple wayOne way is to use thedocument.getElementsByTagName
function. For e.g.Update
There is a far easier way. See @Nick Craver's answer.
You can use
document.links
to get the anchors, then just loop through grabbing thehref
, like this:You can test it out here, you could filter it more before the
.push()
call on the array if you wanted, but that's the concept for grabbing the links and looping through.And here is one way with
getElementsByTagName
:Use: