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?
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 URL is the location of the current document by default, but it can be overridden by the 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/”.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With