8

Currently on my website, I use an HTML base tag to shorten URLs in anchor tags. All URLs on my site belong to one domain. For 100% compliance, I use an absolute URL. for example:

<base href="http://www.example.com/path/to/specialpage/">

I looked on the internet to see if I can somehow shorten this and have it still work in browsers invented within the last 10 years. I wanted to do something like:

<base href="/path/to/specialpage/">

My question is, if I used the above code, would major browsers like Internet Explorer break down? or are there bugs in major browsers with shortening of this tag? I want to try to omit the domain name yet make my site still work with every browser made in the last 10 years, even if it means including a special tag for a specific browser, maybe I need something like:

<!-- firefoxpatchID=1 -->
<base href="/path/to/specialpage/">
<!-- endfirefoxpatch -->

Whats the solution here? could I just get away with omitting the domain and every browser would be happy or do I have to do something special to certain browsers in order to accommodate my idea?

6

No. The href must point to an absolute URI. Relative is not allowed on a base element.

This attribute specifies an absolute URI that acts as the base URI for resolving relative URIs.

The HTML5 standard says, in reference to the href attribute of <base>:

The document base URL of a Document object is the absolute URL

  • 1
    They don't have to be absolute according to this: "The base URL to be used throughout the document for relative URL addresses.... Absolute and relative URIs are allowed." – Stephen Ostermiller Apr 7 '16 at 18:42
  • Being able to specify relative URIs would seem to be a change in HTML5. The spec for HTML 4.01 certainly states this should be an absolute URI. This might be a concern for the OP if they are wanting to support "10 year" old browsers?! – MrWhite Apr 7 '16 at 21:10
  • @StephenOstermiller Well, instead, let's look at the standard which states the href must contain a "document URL" and a document URL is defined as "the absolute URL ". If there are differences, now, compared to HTML 4.01, as pointed out by w3dk, then I don't know and I haven't bothered to look. – Rob Apr 7 '16 at 21:11
  • 1
    I think you need to read the doc a bit further... "The document base URL of a Document object is the absolute URL obtained by running these substeps:" ... "the document base URL is the frozen base URL of the first base element in the Document that has an href attribute". Unfortunately the WhatWG doc does not appear to explain further (at least the internal link for "frozen base URL" has no endpoint). – MrWhite Apr 7 '16 at 23:07
  • 1
    But the spec at w3.org does explain further: "To set the frozen base URL, resolve the value of the element’s href content attribute relative to the Document's fallback base URL; if this is successful, set the frozen base URL to the resulting absolute URL". The "Document's fallback base URL" is basically the absolute URL of the current document. It's a bit wordy, but I take that to mean you can now use relative URLs in the BASE element. The corresponding absolute URL would then be resolved from this. – MrWhite Apr 7 '16 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.