How to check a URL contains a hash or not using JavaScript ?

In this article, the task is to check whether an URL contains or not. This can be done by using the Location hash property in JavaScript. It returns the string which represents the anchor part of a URL including the hash ‘#’ sign.
Syntax:
window.location.hash
Example: This example uses the hash property to check if the URL contains hash or not using javascript.
HTML
| <bodystyle="text-align: center">     <h1style="color: green;">         zambiatek     </h1>      <h2style="font-family: Impact;">         How to check if URL contains an         hash or not using Javascript?     </h2>      <p>         please double click the button:     </p>      <buttonondblclick="mylocation()">         check     </button>      <pid="hash"></p>      <script>         function mylocation() {             if (window.location.hash) {                 alert("Hash(#) component exists");             }             else {                 alert("Hash(#) component doesn't exist");             }         }      </script> </body> | 
Output:
 
Check a URL contains a hash or not
 
				 
					


