找回密碼
 註冊
搜索
查看: 5278|回復: 0

Update a parent window from a child (JavaScript)

[複製鏈接]
發表於 2005-9-28 01:26:39 | 顯示全部樓層 |閱讀模式
Update a parent window from a child

[examplejs1.html]
  1. <HTML><HEAD></HEAD>
  2. <SCRIPT LANGUAGE="JavaScript"><!--
  3. function openChild(file,window) {
  4. childWindow=open(file,window,'resizable=no,width=200,height=400');
  5. if (childWindow.opener == null) childWindow.opener = self;
  6. }
  7. //--></SCRIPT>
  8. <BODY>
  9. <FORM NAME="parentForm">
  10. <INPUT TYPE="button" VALUE="Open child" onClick="openChild('examplejs2.html','win2')"><BR>
  11. <INPUT NAME="pf1" TYPE="TEXT" VALUE=""><BR><INPUT NAME="pf2" TYPE="TEXT" VALUE="">
  12. </FORM></BODY></HTML>
複製代碼

[examplejs2.html]
  1. <HTML><HEAD><SCRIPT LANGUAGE="JavaScript"><!--
  2. function updateParent() {
  3. opener.document.parentForm.pf1.value = document.childForm.cf1.value;
  4. opener.document.parentForm.pf2.value = document.childForm.cf2.value;
  5. self.close();
  6. return false;
  7. }//-->
  8. </SCRIPT>
  9. </HEAD><BODY>
  10. <FORM NAME="childForm" onSubmit="return updateParent();">
  11. <BR><INPUT NAME="cf1" TYPE="TEXT" VALUE="">
  12. <BR><INPUT NAME="cf2" TYPE="TEXT" VALUE="">
  13. <BR><INPUT TYPE="SUBMIT" VALUE="Update parent">
  14. </FORM></BODY></HTML>
複製代碼
You can try it here.

Reference: http://www.rgagnon.com/jsdetails/js-0066.html
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|彩色筆小沛的知識庫

GMT+8, 2024-11-22 03:25 , Processed in 0.023333 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回復 返回頂部 返回列表