Resolving relative URLs in JavaScript

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/b/c/d;p?q and encounter an href value of “../g” (assume there’s no <base> element). The resulting absolute would be: http://a/b/g.

Is there a JS library that does this already? I’d have to believe so.

For more info about what’s needed, the spec:


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