Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yarus23/5379485 to your computer and use it in GitHub Desktop.
Save yarus23/5379485 to your computer and use it in GitHub Desktop.
/**
* Parse hash bang parameters from a URL as key value object.
* For repeated parameters the last parameter is effective.
* If = syntax is not used the value is set to null.
* #!x&y=3 -> { x:null, y:3 }
* @param url URL to parse or null if window.location is used
* @return Object of key -> value mappings.
* @source https://gist.github.com/zaus/5201739
*/
function hashbang(url, i, hash) {
url = url || window.location.href;
var vars = {}, hashes = url.slice(url.indexOf('#!') + 2).split('&');
for(i = hashes.length; i--;) {
hash = hashes[i].split('=');
vars[hash[0]] = hash.length > 1 ? hash[1] : null;
}
return vars;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment