Skip to content

Instantly share code, notes, and snippets.

@deiu deiu/queryVals.js
Created Jun 14, 2016

Embed
What would you like to do?
Parse a URL to map query parameters to their values
// Map URL query items to their values
// e.g. ?referrer=https... -> queryVals[referrer] returns 'https...'
var queryVals = (function (a) {
if (a === '') return {}
var b = {}
for (var i = 0; i < a.length; ++i) {
var p = a[i].split('=', 2)
if (p.length === 1) {
b[p[0]] = ''
} else {
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, ' '))
}
}
return b
})(window.location.search.substr(1).split('&'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.