Skip to content

Instantly share code, notes, and snippets.

@kopepasah
Last active November 4, 2015 13:57
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 kopepasah/87f759866eb78287511d to your computer and use it in GitHub Desktop.
Save kopepasah/87f759866eb78287511d to your computer and use it in GitHub Desktop.
A simple JavaScript helper method for getting the query parameters of a URL and storing those parameters as an object.

Get Parameters

A simple JavaScript helper method for getting the query parameters of a URL and storing those parameters as an object. If no parameters are present, the method will return false.


Author: Justin Kopepasah justin@kopepasah.com
License: MIT https://opensource.org/licenses/MIT

var get_parameters = function() {
var query = window.location.search.replace( '?', '' ),
variables = query.split( '&' ),
parameter = '',
parameters = {};
if ( 0 < query.length ) {
for ( var i = 0; i < query.length; i++ ) {
parameter = variables[i].split('=');
parameters[parameter[0]] = parameter[1];
}
} else {
return false;
}
return parameters;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment