Created
November 24, 2010 12:03
-
-
Save sebarmeli/713549 to your computer and use it in GitHub Desktop.
Parsing the query string given a parameter. Eg. given http://www.domain.com.au?aaa=vvv SA.URL().getQueryValue("aaa") returns "vvv"
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
/* | |
* @author Sebastiano Armeli-Battana (@sebarmeli) | |
* @version 0.2 | |
*/ | |
/*globals window, SA */ | |
if (!window.SA) {window.SA = {}; } | |
SA.URL = (function() { | |
var qstring = window.location.search; | |
return { | |
getQueryValue : function(param) { | |
var qstringArray = qstring && qstring.substring(1).split("&"), | |
i = 0, | |
len = qstringArray.length; | |
for (; i < len; i++) { | |
var token = qstringArray[i], | |
eqIndex = token.indexOf("="), | |
firstPart = token && token.substring(0, eqIndex); | |
if (firstPart === param ) { | |
return token.substring(eqIndex + 1, token.length); | |
} | |
} | |
} | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment