How to get #hash value in a URL in JS

前端 未结 6 1980
小蘑菇
小蘑菇 2020-12-14 18:38

For example, I have a URL as :

http://www.google.com/#hash=value2x

I want a js code to return just value2x. I tried

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 19:12

    How about

    location.hash.split('hash=')[1].split('&')[0]
    

    This will split the hash at hash= and take the value after hash= and before any other argument .

提交回复
热议问题