WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES
Advertisements

How to Check for a Hash (#) in a URL using JavaScript

Topic: JavaScript / jQueryPrev|Next

Answer: Use the Window.location Property

You can simply use the location property of a window (i.e. window.location) to check whether a URL contain hash (#) or fragment component or not in JavaScript.

Let's take a look at the following example to understand how it basically works:

  • <script>
  • if(window.location.hash){
  •     alert("Fragment component exists");
  • } else{
  •     alert("Fragment component doesn't exist");
  • }
  • </script>

Related FAQ

Here are some more FAQ related to this topic:

Advertisements
Bootstrap UI Design Templates

Your Feedback:

We would love to hear from you, please drop us a line.