/* getQueryParam(key) ** Version 1.0, 11/27/2002 ** Author: Cody Burleson ** Tested On: IE 6.0.28 ** ** Retrieves the value of a URL query parameter (key). ** Can parse URL parameter strings with multiple key/value pairs */ function getQueryParam(key) { // The location.search property has a "?" at the start, get the part that follows var queryString = location.search.substring(1, location.search.length); // Check if the param key has been passed var fullKey = key + "="; var startIndexOfFullKey = queryString.indexOf(fullKey); // If it has... if(startIndexOfFullKey!=-1){ var startIndexOfValue = startIndexOfFullKey + fullKey.length; // isolate the "key=" from whatever string remains var isolatedString = queryString.substring(startIndexOfValue,queryString.length); // now we just need to see if any other (extra) params still exist after this one... var indexOfPossibleExtra = isolatedString.indexOf("&") if(indexOfPossibleExtra != -1) { // extra params exist, so we need to drop them... return isolatedString.substring(0,indexOfPossibleExtra); } else { // no extra params exist, we can return what we've got... return isolatedString; } } else { return "-1"; } }