How to check a URL contains a hash or not using JavaScript ? Last Updated : 12 Jan, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 <body style="text-align: center"> <h1 style="color: green;"> GeeksforGeeks </h1> <h2 style="font-family: Impact;"> How to check if URL contains an hash or not using Javascript? </h2> <p> please double click the button: </p> <button ondblclick="mylocation()"> check </button> <p id="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 Comment More infoAdvertise with us Next Article How to check a URL contains a hash or not using JavaScript ? M manaschhabra2 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads JavaScript - How To Check Whether a String Contains a Substring? Here are the different methods to check whether a string contains a substring in JavaScript.1. Using includes() MethodThe includes() method is the most simple and modern way to check if a string contains a specific substring. It returns true if the substring is found within the string, and false oth 3 min read How to Get the Current URL using JavaScript? Here are two different methods to get the current URL in JavaScript.1. Using Document.URL PropertyThe DOM URL property in HTML is used to return a string that contains the complete URL of the current document. The string also includes the HTTP protocol such as ( http://).Syntaxdocument.URLReturn Val 1 min read How to Extract the Host Name from URL using JavaScript? Extracting the hostname from a URL using JavaScript means retrieving the domain part from a complete web address. This can be done using JavaScript's URL object or methods like window.location, which allow easy access to the hostname of a URL.What is URL?A URL (Uniform Resource Locator) is the web a 2 min read How to Check an Object is Empty using JavaScript? These are the following ways that can be used to Check an Object is Empty using JavaScript: 1. Using Object.keys() Method - Mostly usedThe Object.keys() method returns an array that contains the property names of an object. If the length of array is 0, then object is empty.JavaScriptlet obj = {}; if 2 min read How to get URL Parameters using JavaScript ? To get URL parameters using JavaScript means extracting the query string values from a URL. URL parameters, found after the ? in a URL, pass data like search terms or user information. JavaScript can parse these parameters, allowing you to programmatically access or manipulate their values.For getti 3 min read Like