|
| BACK ON TOPIC | Main Page| |
This script looks like the other scripts back on topic, but just is so ingenius, the idea is the next, What happen if we wish to input some fields on a page to give this information to other page, that makes a report or something else, well the functionality is so simple but we do not need to use a server side parser like PHP or CGI and we save again resources and trafic on our server, tha unnecessary querys are maded at Client side.
HOW IT WORKSIt's simple, just include gus_query_string.js on your target page, and call the function getQueryString(), this one makes an array called QUERY['clave'] where stay every field as a key and this Array can be used to write or calculate stuffs on target page, with getQuery('clave') we got an empty string if the KEY value is undefined as datum. Test the example at rigth and as id key put gusgus, is the only picture that can appear
DOWNLOAD THE ZIP FILE WITH 3 EXAMPLES AND THE PICTURE ~ 13k |
BUILD AN EXAMPLE CREDENTIALUSE gusgus AS ID KEY, HAS A PICTURE |
/* This version of JavaScript Query_String can be used by anyone who is not intented
to do profit directly with this code, it means you can not sale the code as is,
you can use it ont your web or php project, or put in a CD Magazine, if you really
do profit with your project and my code consider sharing them :P.
If you want to include the Query_String in some web editor, do not remove this legend.
The lastest version can be found at
http://www.compunauta.com/forums/linux/programacion/java/gus_query_string.html
This is Open and Free Software, madgus@gmail.com, gustavo@compunauta.com
*/
var QUERY=new Object();
function getQueryString(){
var RE = new RegExp('\\+','gi');
var QUERY_STRING=document.location+"";
QUERY_STRING=QUERY_STRING.replace(RE," ");
var QUERY_KEY="VERSION";
var QUERY_DES="2006_madgus@gmail.com";
QUERY[QUERY_KEY]=QUERY_DES;
var vpos;
pos=QUERY_STRING.indexOf("?");
if (pos != -1){
QUERY_STRING=QUERY_STRING.substring(pos+1,QUERY_STRING.length);
while ((pos = QUERY_STRING.indexOf("&"))!=-1){
QUERY_KEY=QUERY_STRING.substring(0,pos);
QUERY_STRING=QUERY_STRING.substring(pos+1,QUERY_STRING.length);
addQuery(QUERY_KEY);
}
if (QUERY_STRING.length!=0){
addQuery(QUERY_STRING);
}
}else{return;}
}
function addQuery(QUERY_KEY){
//this query key is a substring having whole key=escape(val);
vpos=QUERY_KEY.indexOf("=");
if(vpos!=-1){
QUERY_DES=unescape(QUERY_KEY.substring(vpos+1,QUERY_KEY.length));
QUERY_KEY=QUERY_KEY.substring(0,vpos);
QUERY[QUERY_KEY]=QUERY_DES;
}else{
QUERY_DES="";
QUERY[QUERY_KEY]=QUERY_DES;
}
}
function getQuery(QUERY_KEY){
if (QUERY_KEY==""){return "";}
if(QUERY[QUERY_KEY]!=undefined){
return QUERY[QUERY_KEY];
}else {return "";}
}