Click to See Complete Forum and Search --> : How to pass data from pop up into parent page?
Ayien
12-02-2004, 08:37 PM
Hi guys,
Need some help here...I'm stuck....
How is it possible to pass data from pop up window back into the parent page...
For example: I have a field on the parent page, to fill in this filed users will have to click open a pop up window where I
place the info. When users click any option, the data will be pass to the parent page and pop up window will close itself. Thanx in advance.
Exuro
12-02-2004, 09:09 PM
You can use the window.opener property of your new window to access its parent window:
<html>
<head>
<title>Testing</title>
<script type="text/javascript">
<!--
var val=0;
onload = function () {
var win = window.open("","","statusbar=no,resizable=yes,width=350,height=400");
win.document.writeln('<html><body><form>');
win.document.writeln('<input type="text" name="txt1" onclick="window.opener.val = 5;" />');
win.document.writeln('<input type="button" value="Send Value"')
win.document.writeln(' onclick="window.opener.val = this.form[\'txt1\'].value;" />');
win.document.writeln('</form></body></html>');
}
//-->
</script>
</head>
<body>
<form>
<input type="button" value="View Value" onclick="alert(val);" />
</form>
</body>
</html>
7stud
12-03-2004, 05:11 AM
Hi,
How is it possible to pass data from pop up window back into the parent page..
Just to try and clarify things a little bit: with a popup window, there is no parent-child relationship. The parent-child relationship is a relationship that describes frames. Intead, popup windows have an opener-popup window relationship. The Javascript in the popup window can refer to functions and variables on the main page using the 'opener' reference like this:
opener.someFunction();
var a = opener.someVariable;
And, the javascript on the main page can refer to functions and variables in the popup window like this:
var popup = window.open("somepage.htm", "", windowfeatures);
popup.popupFunction();
var b = popup.popupVariable;