The Javascript location hash attribute can be used to either set or retrieve the value following the "#" symbol in the current URL of the browser window. It essentially returns the name of a bookmark within the URL. By using the hash symbol "#" to target a specific anchor tag on the same or other web pages, you can easily navigate to a specific section of a webpage. When a link is clicked, the "#" symbol and bookmark name are appended to the URL. Implementing location.hash or window.location.hash in the target page allows you to access the current bookmark name from the URL, either on page load or upon a click event.
<html>
<head>
<title>Javascript Window Location Hash</title>
<script type="text/javascript" language="javascript">
function getLocationHash()
{
alert(window.location.hash);
}
function setLocationHash()
{
window.location.hash = "#top";
}
</script>
</head>
<body>
<p>
Click here to <a name="top" href="#bottom" style="color: blue"><b>go to Bottom >></b></a> <br />
Sample Text Sample Text Sample Text Sample Text Sample Text Sample Text <br />
</p>
<p>
Click here to <a name="bottom" href="#top" style="color: blue"><b>go to Top</b></a>
</p>
<input type="button" onclick="getLocationHash();" value="get Location Hash" />
<input type="button" onclick="setLocationHash();" value="set Location #Top" />
</body>
</html>