I want to parse the hash fragment into an associative array in javascript, just like the $_GET superglobal in PHP.
Here is the URL:
www.mysite.com/randompage#name=donald&lastname=mclotsoquestions&age=25
So far I have this:
var hashfragment = location.hash;
var hashfragment_array = hashfragment.split('&');
Hashfragment_array is [“#name=donald”,”lastname=mclotsoquestions”,”age=25″]
How can I create key value pairs from this?
Use jQuery BBQ, which is a battle-tested library that handles state management.
It also makes adding or changing the fragment easy: