How to Check for a Hash (#) in a URL using JavaScript
Window.location
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.
window.location
#
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>
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Use the
Window.locationPropertyYou 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:
need an explanation for this answer? contact us directly to get an explanation for this answer