Skip to content

Instantly share code, notes, and snippets.

@mephraums
Last active December 22, 2015 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mephraums/6445607 to your computer and use it in GitHub Desktop.
Save mephraums/6445607 to your computer and use it in GitHub Desktop.
Javascript - URL Params Anonymous function Object
var urlParams = {};
(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).toLowerCase();
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
}());
//Usage urlParams['q'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment