Maximus Maximus - 1 year ago 62
HTML Question

What's the difference between different combinations of slashes in base tag href attribute

I've noticed that a browser behaves differently if I mix slashes in the

attribute of
tag. I know what
tag is used for. I'm wondering what's the difference in terms how a browser resolves the path in the following configurations:

<base href="">
<base href="">
<base href="/homework">
<base href="/homework/">
<base href="homework/">
<base href="homework">

Answer Source

You can just test it:

var base = document.head.appendChild(document.createElement('base')),
    a = document.body.appendChild(document.createElement('a')),
    urls = ["", "", "/homework", "/homework/", "homework/", "homework"];
a.href = "foo";
for (var url of urls) {
  base.href = url;
  console.log('Using base: ' + url + '\nRelative URL: foo\nAbsolute URL: ' + a.href);
} { max-height: 100%; }

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download