Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get "raw" href contents in JavaScript

I am trying to write a GreaseMonkey script in which I want to find all of the links that are relative links. It seemed to me that the way to do that would be to match the contents of href against /^https?:///.

But I find that when I access the anchor's href attribute, it's always normalized or cooked into a form that contains "http". That is, if the HTML contains:

<a id="rel" href="/relative/link">inner</a> 

accessing

document.getElementById("rel").href 

returns

http://example.com/relative/link 

How can I access the raw data in the href attribute?

Alternately, is there a better way to find relative links?

like image 445
wfaulk Avatar asked Oct 11 '09 15:10

wfaulk


1 Answers

Try the getAttribute method instead.

like image 149
Gumbo Avatar answered Sep 29 '22 03:09

Gumbo