|
Update a parent window from a child
[examplejs1.html] - <HTML><HEAD></HEAD>
- <SCRIPT LANGUAGE="JavaScript"><!--
- function openChild(file,window) {
- childWindow=open(file,window,'resizable=no,width=200,height=400');
- if (childWindow.opener == null) childWindow.opener = self;
- }
- //--></SCRIPT>
-
- <BODY>
- <FORM NAME="parentForm">
- <INPUT TYPE="button" VALUE="Open child" onClick="openChild('examplejs2.html','win2')"><BR>
- <INPUT NAME="pf1" TYPE="TEXT" VALUE=""><BR><INPUT NAME="pf2" TYPE="TEXT" VALUE="">
- </FORM></BODY></HTML>
複製代碼
[examplejs2.html]-
- <HTML><HEAD><SCRIPT LANGUAGE="JavaScript"><!--
- function updateParent() {
- opener.document.parentForm.pf1.value = document.childForm.cf1.value;
- opener.document.parentForm.pf2.value = document.childForm.cf2.value;
- self.close();
- return false;
- }//-->
- </SCRIPT>
- </HEAD><BODY>
- <FORM NAME="childForm" onSubmit="return updateParent();">
- <BR><INPUT NAME="cf1" TYPE="TEXT" VALUE="">
- <BR><INPUT NAME="cf2" TYPE="TEXT" VALUE="">
- <BR><INPUT TYPE="SUBMIT" VALUE="Update parent">
- </FORM></BODY></HTML>
複製代碼 You can try it here.
Reference: http://www.rgagnon.com/jsdetails/js-0066.html |
|