Forked from miohtama/parse-hash-bang-arguments-in-javascript.js
Last active
August 29, 2015 13:56
-
-
Save lorddev/9007310 to your computer and use it in GitHub Desktop.
Useful for ajax navigation
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. | |
* | |
* #x&y=3 -> { x:null, y:3 } | |
* | |
* @param aURL URL to parse or null if window.location is used | |
* @return Object of key -> value mappings. | |
*/ | |
function parseHashBang(url) { | |
url = url || window.location.href; | |
var collection = []; | |
var queryString = url.slice(url.indexOf("#!") + 2); | |
var pairs = queryString.split("&"); | |
pairs.forEach(function (element) { | |
var pair = element.split("="); | |
var key = pair[0]; | |
var val = pair[1]; | |
collection[key] = val; | |
}); | |
return collection; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment