How can I retrieve the full URL to which an anchor links using jQuery / JavaScript consistently across all browsers? For example, I want to return http://www.mysite.com/mypage.aspx
from <a href="../mypage.aspx"></a>
.
I have tried the following:
$(this).attr('href')
: The problem is that jQuery returns the exact value of the href (i.e.,../mypage.aspx
).this.getAttribute('href')
: This works in Internet Explorer, but in FireFox it behaves the same as above.
What is the alternative? I cannot simply append the current site's path to the href value because that would not work in the above case in which the value of the href escapes the current directory.