Thursday, July 28, 2005 4:20 PM triplez

QueryString in JavaScript

JavaScript doesn't have anything to get back the querystring from the url, so here's a source code that works perfectly to get the querystring.

"javascript">
//This is the script to take querystrings from the URL and convert them 
//into a Javascript array. "?search=whatever" becomes querystring["search"] 

//this loads the portion of the url containing the querystring, and also
//decodes any special character codes  
var que = unescape(location.search)  ;

//remove the ? from the beginning of the string
var que = que.substring(1, que.length);

//detects multiple values and splits them into an array que[0], que[1] etc
var que = que.split("&");

// creates the querystring array
var querystring = new Array();

//(for some strange reason the "for/next" loop wasn't working)
var loop = 0;

//This loop takes each value in the que array then seperates the "names" 
//from the "values" by splitting it into "inter" arrays. the name becomes
// "inter3" and the value becomes "inter2". querystring then loads the 
// "inter2" value into a slot called "inter3"
while (loop "=");
   var inter2 = inter[1];
   var inter3 = inter[0]
   que[loop] = inter2;
   querystring[inter3] = inter2
   loop = loop + 1;
 } ;
//(C) Samuel Loy
// --!>

Filed under:

# re: QueryString in JavaScript

Saturday, August 20, 2005 1:38 AM by rattler108

I have a question
I am using javascript to open a new window and display a picture on my asp.net application. What I am doing on my aspx page is that I am sending a querystring called inversion that is used to search for the folder where the pictures are stored. I got it to work on my code in the aspx and it takes the querystring to search for the folder and display the thumbnail pictures, but I have been unable to do so on javascript to display the full blown picture. Here is the code that I am using:

<script language="JavaScript">

function NewWindow(url, w, h)
{

// If you place Thumb.aspx in a different directory that your root image directory,
// you will need to add the image directory to url below, like:
// url = "/rootImageDirectory/" + url + ".jpg"

url = "Galeria/" + url + ".jpg"
if (w > screen.width || h > screen.width)
{
if (w > screen.width && h <= screen.height)
{
var nw = screen.width - 70;
var nh = parseInt(h) + 36
}
if (h > screen.height && w <= screen.width)
{
var nh = screen.height - 70;
var nw = parseInt(w) + 36
}
if (w > screen.width && h > screen.height)
{
var nh = screen.height - 70;
var nw = screen.width - 70;
}

window.open(url,"_blank","width=" + nw + ",height=" + nh + ",left=0,top=0,scrollbars=yes,resizable=yes");

}
else
{
var nh = parseInt(h) + 25;
var nw = parseInt(w) + 25;
window.open(url,"_blank","width=" + nw + ",height=" + nh + ",scrollbars=no,resizable=no");
}
}

</script>

what I need is for the function in javascript where it says url to also contain the name of the folder that I get using the querystring from the previous page. Could you please help me with this?