The hash hasvas property indicates the value from the hash symbol "#" in the current URL of the browser window. Javascript location addresses actually return the bookmark name with the current URL. The hash tab hash icon provides functionality for targeting a named HTML tag on the same other web pages. When you click on any link text that targets bookmarks on any web page, it adds the “#” symbol and the name of the bookmark to the end of the URL. You can put the location.hash or window.location.hash code on the landing page to get the current bookmark name from the URL. You can call the function when the page loads or click the button 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>
source share