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

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

From: Anne van Kesteren <annevk@annevk.nl>
Date: Thu, 11 Jul 2013 10:59:38 -0400
Message-ID: <CADnb78gd9-ay0sN+x8dO_P+mJYJ0dK088GbCaVT0UnGaLcKh3A@mail.gmail.com>
To: Jake Archibald <jaffathecake@gmail.com>
Cc: WHATWG <whatwg@whatwg.org>
On Thu, Jul 11, 2013 at 7:56 AM, Jake Archibald <jaffathecake@gmail.com> wrote:
> http://url.spec.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)?

document.baseURI?


> 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>.
>
> So:
>
> <img src="cat.gif">
> new URL('cat.gif').href == document.querySelector('img').src;
>
> And:
>
> if (new URL('cat.gif').href !== new URL('cat.gif', location.href).href) {
>   // something is modifying the base url
> }

I think I'd prefer consistent results for the constructor across
scripts if you omit a base URL.


--
http://annevankesteren.nl/
Received on Thursday, 11 July 2013 15:00:03 UTC

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