Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override <base> tag without removing the tag itself?

Tags:

I'm trying to add some hash links (in the format of a content table, to be able to facilitate webpage navigation) to this site in which a <base> tag is used.

Now obviously due to the base tag, every other relative tag will be relative to the base tag href. In order for me to create this internal content table with the links pointing to different parts of the specific page, I need to get the default URL (before base tag is in effect) so the internal links can work properly.

Is there a way to do get around the base tag and accomplish this?

like image 668
sSmacKk Avatar asked Sep 06 '12 15:09

sSmacKk


People also ask

How do you override base tags?

The effect of the base tag is global to the document, and the only way to override the effect of <base href="..."> is to use absolute URLs. You can use window. location in JavaScript to get the URL of the page itself, in case the document was retrieved via HTTP. And you could use it to construct absolute URLs.

Which tag used to override base URL method?

The base URL is the location of the current document by default, but it can be overridden by the base tag.

How do you use a base tag?

The HTML base tag is used to specify a base URI, or URL, for relative links. This URL will be the base URL for every link on the page and will be prefixed before each of them. For example, if the URL specified by the base tag is “www.xyz.com” and then every other URL on the page will be prefixed by, “www.xyz.com/”.


1 Answers

The effect of the base tag is global to the document, and the only way to override the effect of <base href="..."> is to use absolute URLs.

You can use window.location in JavaScript to get the URL of the page itself, in case the document was retrieved via HTTP. And you could use it to construct absolute URLs.

The base tag is normally not needed these days. It is better to use server-side technologies that let you construct addresses from one or more base addresses. So quite possibly the best approach is to get rid of the tag.

like image 149
Jukka K. Korpela Avatar answered Oct 05 '22 17:10

Jukka K. Korpela