Pretty simple way to parse query string parameters into an object for access in JavaScript.
1/*
2 * Params.js
3 *
4 * Super simple parser of query string parameters.
5 * Creates a variable 'params' on the 'window' object.
6 *
7 */
8(function() {
9 var params = {},
10 capture = void 0,
11 query = window.location.search.substring(1),
12 whitespace = /\+/g,
13 regex = /([^&=]+)=?([^&]*)/g,
14 decode = function(s) {
15 return decodeURIComponent(s.replace(whitespace, " "));
16 };
17
18 while (capture = regex.exec(query)) {
19 var key = decode(capture[1]),
20 value = decode(capture[2]);
21
22 if (value !== '') {
23 params[key] = value;
24 }
25 }
26
27 this.params = params;
28}).call(this);