Apparently I'm the new MoD of Javascript. I'll try not to become drunk with this new Found Powa.
Here's a sample source i wrote a long time ago. Basicly, it allows you to grab querystring data with javascript. Pretty useful when you need a dynamic site and need to pass data back and forth and it has to work offline.
Here's a Link to my Personal SourceCode Archive. Since i'm a freelancer, I like to have my personal scripts available when I need them. Rape and Pillage my poor CodeChive.
http://www.cybernerdz.net/sites/cchive/
- Code: Select all
//script by pedro 'vor' sousa
var parms = request(); //lets get our parms
//Output all the Parms Sent to the Page
if(! isArray(parms)){ //if not an array
document.write("No Parms");
}else{ //ITs an Array !
for(var item in parms){
document.write("[" + item + ] = " + parms[item] + "
");
}//end for
}//end if
//FUNCTION ==========================================================
//Put all parms after ? into an array. (same as in ASP)
function request(){
var parmList = document.location.search;//get the parms after the ?
if(parmList != ""){//do we have any parms in the var
parmList = parmList.replace("?","")//Lets get rid of the question mark
var pat = /\+/gi; parmList = parmList.replace(pat," ")//Lets replace all + to spaces
parmList = parmList.split("&"); //Lets divide each var/value
//Create a Hash Array
var ary = new Array(),tary;
for(var x=0;x < parmList.length;x++){
tary = parmList[x].split("="); //divide the var and value
if(tary.length == 2){// only if we have 2 elements
ary[tary[0]] = unescape(tary[1]); //Fix any UrlEncoding
}// end if
}//end if
return ary;
}else{ //We dont have any parms
return "";
}//end if
}// end function
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//checks to see if variable is an Array
function isArray(check){
if(typeof check == "object"){
return(parms.constructor.toString().match(/array/i) != null);
}//end if
return false;
}//function