Skip to content

Instantly share code, notes, and snippets.

@chrisdeely
Created April 16, 2013 21:19
Show Gist options
  • Save chrisdeely/5399729 to your computer and use it in GitHub Desktop.
Save chrisdeely/5399729 to your computer and use it in GitHub Desktop.
Javascript snippet to read URL query string parameters
var urlParams = {};
//Parse URL parameters
(function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
console.log( urlParams.foo, urlParams.bar );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment