Isaac Lubow
Isaac Lubow

Reputation: 3573

What's the best way to check for the presence of a hash?

Right now I'm using

if(window.location.hash != '')

Is this foolproof? Or, is there a way to return a Boolean value instead?

Upvotes: 1

Views: 84

Answers (1)

RaYell
RaYell

Reputation: 70404

window.location.hash will return empty string if the hash symbol is present in the URL but it doesn't have anything on it's right side. If there's a value it will return the value with the hash symbol as first character. This might be a bit confusing in certain situations.

Part from that I'd say it's a pretty solid way of using it.

Upvotes: 1

Related Questions