Forked from zaus/parse-hash-bang-arguments-in-javascript.js
Created
April 13, 2013 18:20
-
-
Save yarus23/5379485 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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