JDP 發表於 2005-9-28 01:26:39

Update a parent window from a child (JavaScript)

Update a parent window from a child



<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>


<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
頁: [1]
查看完整版本: Update a parent window from a child (JavaScript)