For example, I have a URL as :
http://www.google.com/#hash=value2x
I want a js code to return just value2x. I tried location.hash.split('=')[1] but that results the first hash value like if url is
value2x
location.hash.split('=')[1]
http://www.google.com/#hfh=fdg&hash=value2x
It returns fdg&hash. I want just the value of hash.
fdg&hash
hash
NO jQuery Please.
Thanks for the help in advance.
function getHashValue(key) { var matches = location.hash.match(new RegExp(key+'=([^&]*)')); return matches ? matches[1] : null; } // usage var hash = getHashValue('hash');
2.1m questions
2.1m answers
60 comments
57.0k users