PDA

View Full Version : parameter from main browser to popup



detieubao
04-21-2006, 10:59 AM
I create 2 pages:
*** page 1 as following:
<head>
<script language='javascript'type='text/javascript'>
function openPopup()
{
var popup = open('page2.htm', 'page2');
txt = document.getElementById('txtParam');
popup.document.all.txtReceive.innerHTML = txt.value;
}
</script>
</head>
<body>
Paramater : &nbsp <input id="txtParam" type="text">
<input id='button1' type='button' value='Open' onclick="openPopup();">
</body>

*** page 2 as following:
<body>
<table border="1" width="100%" id="table1">
<tr>
<td width="179">Receive Parameter:</td>
<td id='txtReceive'> </td>
</tr>
</table>
</body>

With the code above, I want to pass parameter from a browser to a popup. But it just works on local, doesn't work on web server. I don't know the reason why. So I don't know how to fix.
Please help solve this problem

jscheuer1
04-21-2006, 07:55 PM
On page one have:


<input type="text"><input type="button" value="click" onclick="window.open(page2.htm?var1='+this.previousSibling.value)">

On page2.htm have:



<span id="rec"></span>
<script type="text/javascript">
if (location.search.indexOf('?var1=')>-1)
document.getElementById('rec').innerHTML=unescape(location.search).replace(/^.?var1=/, '')
</script>

detieubao
04-24-2006, 02:44 AM
Thank a lot for your help.
But in the case I want to pass many parameters to the second page, would you please to tell me the solution.
By the way, would you please to explain for me the reason 2pages I've coded just work properly on local drive?

jscheuer1
04-24-2006, 07:16 AM
Hard to say, it might be your server. In any case, your code is probably IE specific, with its use of 'document.all' and employs the window.open() method in a shorthand sort of way that could be trouble. Another thing is that when passing info between windows, browsers can get pretty picky about just what refers to what. Just playing around, this scheme worked in IE, Opera and FF on one of my servers as well as locally and could be expanded to accommodate any number of variables. ONLY problem is, it REQUIRES javascript (PHP is generally better for this sort of thing):


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<!-- saved from url=(0014)about:internet -->
<!-- this and above comment should be removed for live, non-demo use -->
<head>
<title>page1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function openPopup(){
var txt = document.getElementById('txtParam');
window.passed1 = txt.value;
var popup = window.open('page2.htm', 'page2', 'width=400, height=300');
}
</script>
</head>
<body>
Paramater : &nbsp <input id="txtParam" type="text">
<input id='button1' type='button' value='Open' onclick="openPopup();">
</body>
</html>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<!-- saved from url=(0014)about:internet -->
<!-- this and above comment should be removed for live, non-demo use -->
<head>
<title>page2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
onload=function(){
document.getElementById('txtReceive').innerHTML=opener.passed1;
}
</script>
</head>
<body>
<table border="1" width="100%" id="table1">
<tr>
<td width="179">Receive Parameter:</td>
<td id='txtReceive'> </td>
</tr>
</table>
</body>
</html>

detieubao
04-24-2006, 08:05 AM
My English is not good. So I cannot talk any sentence better than "Thank a lot". Anyway, thanksssss you a lot.