window.opener 返回的是建立當前窗口的那個父窗口的引用,好比點擊了a.htm上的一個連接而打開了b.htm,而後咱們打算在b.htm上輸入一個值而後賦予a.htm上的一個id爲「name」的textbox中,就能夠寫爲:indow.opener.document.getElementById("name").value = "輸入的數據";
1.頁面代碼:javascript
<html> <head> <title>無標題文檔title> </head> <script> function tanchu() { window.open("Untitled-5.html"); } </script> <body> <form id="form1" name="form1" method="post" action=""> <label> <input type="submit" name="button" id="button" value="提交" onclick="tanchu()" /> </label>
<label> <input type="text" name="textfield" id="textfield" /></label> </form> </body> </html>
2.子頁面代碼:html
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔title> head> <script language="javascript"> function aaa() { window.opener.document.getElementByIdx('textfield').value='123123123'; } script> <body> <form id="form1" name="form1" method="post" action=""> <label> <input type="submit" name="button" id="button" value="提交" onclick="aaa()" /> label> form> </body> </html>