Skip to content

Instantly share code, notes, and snippets.

@nathansearles
Created January 15, 2015 17:34
Show Gist options
  • Save nathansearles/09f76e4257e0d8a57741 to your computer and use it in GitHub Desktop.
Save nathansearles/09f76e4257e0d8a57741 to your computer and use it in GitHub Desktop.
Get Query String
/*
* Example URL: http://example.com/?city=portland&state=oregon&country=usa
* Example Usage: alert( getQueryString('city') ); will return portland
*/
function getQueryString(obj) {
var string = window.location.search.substring(1);
var strings = string.split('&');
for (var i=0; i < strings.length; i++) {
var set = strings[i].split('=');
if (set[0] == obj) {
return set[1];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment