javascript - Is the a.href property always returned as absolute? -


in following html:

<a id="link" href="page.htm">page</a> 

i'm finding document.getelementbyid("link").href returns absolute path page.htm rather relative path have typed it. see http://jsfiddle.net/4hgaw/.

can guarantee javascript return absolute path, in every browser?

the reason i'm asking i'm grabbing http://www.... part check domain link points to, , need work internal links well.

yes, relevant browsers return qualified url.

if want retrieve original value of href attribute ('page.html' in case), can this:

anchor.getattribute('href') 

however, doesn't seem work in older versions of ie (8 , below).

live demo: http://jsfiddle.net/simevidas/4hgaw/1/


Comments