Created
January 15, 2015 17:34
-
-
Save nathansearles/09f76e4257e0d8a57741 to your computer and use it in GitHub Desktop.
Get Query String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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