开发者

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

开发者 https://www.devze.com 2023-01-15 08:15 出处:网络
Right now I\'m using if(window.locatio开发者_开发问答n.hash != \'\') Is this foolproof? Or, is there a way to return a Boolean value instead?window.location.hash will return empty string if the h

Right now I'm using

if(window.locatio开发者_开发问答n.hash != '')

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消