Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url Hash with Html Base Tag

window.location.hash

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.

Html Base Tag

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?

like image 426
brad Avatar asked Mar 18 '09 16:03

brad


People also ask

How do I find the base URL in HTML?

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.

What is a Hash link HTML?

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 “#”.

What is the base tag in HTML and example?

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/”.

How do I find base URL?

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.


1 Answers

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.

like image 138
Ken Browning Avatar answered Sep 24 '22 03:09

Ken Browning