Use this:
var hash_array = location.hash.substring(1).split('&'); var hash_key_val = new Array(hash_array.length); for (var i = 0; i < hash_array.length; i++) { hash_key_val[i] = hash_array[i].split('='); }
Now hash_key_val[index] is an array of two elements, where the first element is the name of the key parameter, and the second is the corresponding value.
Edit:
After some time, having studied this case, I felt that I needed to rewrite it - to return an object instead of an array of arrays. I see that the balafi have done this before, but I cannot bear to make my answer so contradictory and legible. Full example in fiddle . Function source here:
function getParameters(location) { if (typeof location === 'undefined') { location = window.location; } var hashParams = new (function Params() {})(); if (location.hash.length === 0) { return hashParams; }; var hashArray = location.hash.substring(1).split('&'); for (var i in hashArray) { var keyValPair = hashArray[i].split('='); hashParams[keyValPair[0]] = keyValPair[1]; } return hashParams; }
source share