W3C home > Mailing lists > Public > whatwg@whatwg.org > July 2013

[whatwg] [URL] Resolving against the base of the current page

From: Jake Archibald <jaffathecake@gmail.com>
Date: Thu, 11 Jul 2013 12:56:06 +0100
Message-ID: <CAJ5xic8_tsiXcYhOxSAqCEWZ1=hVeeuRpaWYOVREDt4cL0ZaFQ@mail.gmail.com>
To: WHATWG <whatwg@whatwg.org>

How would I create a URL relative to the page, but taking into account
<base> (and anything else that may affect relative urls on the page)?

It feels like the 2nd constructor parameter should default to the page's
base url, and you could pass window.location.href in if you wanted to
override <base>.


<img src="cat.gif">
new URL('cat.gif').href == document.querySelector('img').src;


if (new URL('cat.gif').href !== new URL('cat.gif', location.href).href) {
  // something is modifying the base url

Received on Thursday, 11 July 2013 11:56:32 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:03 UTC