Click to See Complete Forum and Search --> : passing info into a new window opened by JS


etheracide
12-02-2003, 02:46 PM
I write primarily using PERL, but my new script requires sized windows for which I am using JavaScript to fully control the size of the new window and what it has (such as toolbar, location, status, etc...).

Here is the simple JavaScript that I am using:

<SCRIPT LANGUAGE=JAVASCRIPT TYPE=\"TEXT/JAVASCRIPT\">
<!-- Hide from older browsers


function anothernewWindow() {
imWindow = window.open('IM_window.cgi?username=$username&password=$password&pal=$pal&add=no', 'imwin2', 'toolbar=no,location=no,scrollbars=no,resizable=yes,width=500,height=350')
}


// End hiding script -->
</script>


And I use the following a href to open said window:
<a href=\"javascript:anothernewWindow()\"><span class=subheaders>$pal</a>

Th problem I encounter is that I can't recall how to send the $username, $password and $pal values to the JavaScript-opened window. The window opens up a script which is expecting those values to be in there, but how do I send the values using the JavaScript?

Thank you to anyone that even looks this over.

Pittimann
12-02-2003, 04:17 PM
Hi!

In your code fragments the variables which you want to send to the new window are not defined. No form there (because of that: no fieldnames, nothing to "tell" your new window the values of the variables).

Your function "anothernewWindow()" should be called onsubmit of a form and the values of the formfields be properly integrated to the url.

If you posted some more code, you will surely get a solution - maybe not by me - have to got to bed soon...

Cheers - Pit

edelmatt
12-02-2003, 05:48 PM
Or, so it appears.

You can use JavaScript in the new window to dissect its own URL to get those parameter name/value pairs.

Here is the URL:
IM_window.cgi?username=$username&password=$password&pal=$pal&add=no'

You can use an onload routine to get the URL and pull it apart:

//put the URL into a string var
urlString = location.href;

//make an array by splitting the URL at the "?"
split1 = urlString.split("?");

//use only the 2nd member of the array, as that
//will be the name/value pair portion
//and split that string by the "&" characters
split2 = split1[1].split("&");

for (i in split2)
{
//split each name/value by its equal sign
split3 = split2[i].split("=");
if (split3[0] == "username")
{
//put the username value into a JS variable
usernameVar = split3[1];
}
//use other if, or else-if blocks here to find
//and use other name/values from the URL
}