kbec
kbec

Reputation: 3465

How to get definitive url from href value?

I have some links with various hrefs and want to get definitive url for this value, like:

http://localhost/   -> http://localhost/
localhost           -> http://mysite.example/localhost
firstpage           -> http://mysite.example/firstpage
/anotherpage        -> http://mysite.example/anotherpage
#anchor1            -> http://mysite.example/currentpage#anchor1
/#anchor2           -> http://mysite.example/#anchor2

BTW I don't want code for click handling. I can do that.

Upvotes: 2

Views: 382

Answers (1)

wrock
wrock

Reputation: 1349

$("a:first").prop("href") will give you the full URL of your first anchor tag as opposed to $("a:first").attr("href") which will give you the text in the href attribute.

Upvotes: 5

Related Questions