0

Using Javascript how do you check if current URL contains an hash?

In test page I want to add a Javascript code to print:

<p>yes, there is a hash here</p>

if hash is present (current page http://www.example.com/test/#abc) or:

<p>no, there is no hash here</p> 

if hash is not present (current page http://www.example.com/test/).

Monzio
  • 49
  • 10

1 Answers1

1

It's straightforward

if(window.location.hash) {
   //# in URL
} 
Navoneel Talukdar
  • 4,393
  • 5
  • 21
  • 42