Looking for a way to parse key pairs out of the hash/fragment of a URL into an object/associative array with JavaScript/JQuery
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- jQuery add and remove delay
Do this in pure Javascript:
You might want to check out jsuri. It seems to work well for me.
You can also use the .hash property, demonstrated in this scrolling table of contents example for a clicked link or for the locatioin.
I was looking through a bunch of answers for this problem and wound up cobbling them together using one line with
reduce
:There's obviously a lot going on in that one line. It can be rewritten like this for clariry:
Here it is, modified from this query string parser:
No JQuery/plug-in required
Update:
I'm now recommending the jQuery BBQ plugin as per Hovis's answer. It covers all hash parsing issues.
This jquery API does parse hash tags: https://jhash.codeplex.com/