如何檢索錨鏈接在所有瀏覽器中始終如一使用jQuery/JavaScript進行鏈接的完整URL?例如,我想從<a href="../mypage.aspx"></a>
返回http://www.mysite.com/mypage.aspx
。使用jQuery/JavaScript從超鏈接獲取完整URL
我曾嘗試以下:
$(this).attr('href')
:問題是,jQuery的返回HREF(即,../mypage.aspx
)的精確值。this.getAttribute('href')
:這適用於Internet Explorer,但在FireFox中的行爲與上述相同。
什麼是替代方案?我不能簡單地將當前網站的路徑附加到href值,因爲在上述href的值轉義當前目錄的情況下,這不起作用。
http://stackoverflow.com/questions/303956/jquery-select-a-which-href-contains-some-string –
的可能重複你可能要檢查這個問題http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue –
@sputnick,它絕對不是重複的。這看起來像表面上基本的n00bert url propery問題,但它稍微複雜一些。 –