Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this 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>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Convert a Float Number to a Whole Number in... >>
<< How to Allow Only Numeric Value in HTML Text Input...