Passing text string to a new window?

J

johkar

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:eek:penWin('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>
 
K

kaeli

Would there ever be any problems with the following script depending
on what type of characters are in the text string?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top