Resolving relative URLs in JavaScript

后端 未结 3 503
傲寒
傲寒 2021-01-03 11:48

I\'m building a JS library which has a requirement of looking at form[action] and a[href] values and resolving them into absolute URLs.

For example, I\'m on http://a

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-03 12:06

    It turns out that the .href attribute of a A element (not .getAttribute('href'), but .href) returns the resolved (absolute) URL.

提交回复
热议问题