When using a link for a javascript action, I usually do something like this:
<a href="#">Link Text</a>
That way, when someone clicks the link before the page loads nothing terrible happens.
On my current project I use this same construct, but with a base tag:
<html>
<head>
<base href="http://example.com/" />
</head>
<body>
<a href="#">Link Text</a>
</body>
</html>
However, if the page url is:
http://example.com/dir/page
clicking the link navigates to
http://example.com/#
rather than
http://example.com/dir/page#
How can I fix this?
The <base> tag specifies the base URL and/or target for all relative URLs in a document. The <base> tag must have either an href or a target attribute present, or both. There can only be one single <base> element in a document, and it must be inside the <head> element.
Anchor (hash link) is a bookmark link, which, when clicked, forces the server to redirect page to the desired page or “anchored” place. The name “hash-link” is used because it includes the symbol “#”.
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/”.
To find the base URL of your website, go to the site's front page. What you see in the address bar on your site's front page is the base URL of your website.
Either remove your base
tag or change your href
attributes to be fully qualified. What you are observing is the intended behavior when you mix base
with a
elements.
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