Created
March 2, 2017 16:27
-
-
Save evolutionxbox/0eb2fb4fae74651499076e4936faa3ed to your computer and use it in GitHub Desktop.
Get URL params (querystring), returns object
This file contains 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
// Get URL params (querystring) | |
if (!location.params) { | |
Object.defineProperty(location, 'params', { | |
enumerable: false, | |
get: function () { | |
var search = location.search; | |
var all = /(?:[?&;])(?:[^&;#]+)/g; | |
var pair = /[?&;]([^&;=#]+)=?([^&;#]*)/; | |
var results = {}; | |
search.match(all).forEach(function (param) { | |
var match = pair.exec(param); | |
results[match[1]] = match[2]; | |
}); | |
return results; | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment