readGET()

The purpose of this script is to read data from a URL (ie, from a GET method) without relying on Tcl or some other server side language.

There is no limit on how many variables it can read, and it will create variables with the names and values of those passed through the url. So, for example, if the url contains ?var1=a&var2=b, you will have two vars available to you named var1 and var2 with values of 'a' and 'b' respectively.

Note that if you wish the variables to be available to you outside of the readGET function, it must not be a function, just linear javascript read as the page loads.

Example: http://slayer.office.aol.com/getReader/index.html?var1=1&var2=2
Example vars are hardcoded. change the values if you like, but changing the names will throw an error. The script assumes that you know what variables are being passed.


function readGET() {
theURL = location.href;
varBegin = theURL.indexOf('?');
if (varBegin != -1) {
urlData = theURL.substring(varBegin+1,theURL.length);
dataArray = urlData.split('&');
dataArrayLen = dataArray.length;

for (i=0;i<dataArrayLen;i++){

eq = dataArray[i].indexOf('=');
tempVar = dataArray[i].substring(0,eq);
tempEq = dataArray[i].substring(eq + 1,dataArray[i].length);
eval(tempVar + "=" + 'tempEq');
}
}
}

home