Connecting Tech Pros Worldwide Forums | Help | Site Map

Passing text string to a new window?

johkar
Guest
 
Posts: n/a
#1: Jul 23 '05
Would there ever be any problems with the following script depending
on what type of characters are in the text string? I am appending the
value of hidden form field to the query string.

//Assume JavaScript enabled browsers and popups allowed.
//Function to open the window
function openWin(elm){
var nHeight = 250;
var nWidth = 250;
var nXpos = (screen.availWidth - nWidth) / 2;
var nYpos = (screen.availHeight - nHeight) / 2;
var desc=document.myForm.elements[elm].value;
var statusPopup = window.open('description.htm?desc=' +
desc,'popupWin','top=' + nYpos + ',left=' + nXpos + ',screenY=' +
nYpos + ',screenX=' + nXpos + ',height=' + nHeight + ',width=' +
nWidth + 'location=no,menubar=no,resizable=no,scrollbars=no ,statusbar=no,toolbar=no');
}
<!-- Link example to call the function and hidden field -->
<a href="javascript:openWin('longdesc2')">Description </a>
<input type="hidden" name="longdesc2" value="This is some text of Joe
Cool's & Jane Doe's." />

The is the script in the new window.

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<script language="javascript" type="text/javascript">
var description=location.href.split('desc=');
if(description[1])
document.write(description[1].replace(/%20/g," "));
</script>
</body>
</html>

kaeli
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Passing text string to a new window?


In article <e5daa16c.0410301253.2acbda4@posting.google.com> ,
nosendjunk@msn.com enlightened us with...[color=blue]
> Would there ever be any problems with the following script depending
> on what type of characters are in the text string?[/color]

Yes. You have to URL encode any value you send IF you're forming the URL
yourself instead of using GET for a form.
The ampersand would be a very big problem. It's a field separator for form
values.

If you use a form and use GET, it automatically encodes the values and puts
them in the URL. I find this way to be the safest and easiest way to handle
querystring params with unknown values, myself.
You could just open a new window and set that as the target to a form and
submit the form onclick instead of what you're currently doing.

HTH

--
--
~kaeli~
To steal ideas from one person is plagiarism; to steal from
many is research.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

johkar
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Passing text string to a new window?


Thanks for the insights.

John
Closed Thread


Similar JavaScript / Ajax / DHTML bytes