window.opener.document.getElementById
window.opener 的用法
window.opener 返回的是建立當前視窗的那個父視窗的引用,比如點選了a.htm上的一個連結而開啟了b.htm,然後我們打算在b.htm上輸入一個值然後賦予a.htm上的一個id為“name”的textbox中,就可以寫為:indow.opener.document.getElementById("name").value = "輸入的資料";
1.頁面程式碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
< 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 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.子頁面程式碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
< 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 > |