子ウィンドウから親ウインドウに値を渡す
親ウィンドウがFrameになっていて、そのFrameの中のHTML等から
子ウィンドウを開き、その子ウィンドウから親ウィンドウに値を渡したい場合。
■Main
<html> <head> <frameset> <frame src="xxx1.html" name="frame1"> <frame src="xxx2.html" name="frame2"> </frameset> </head> </html>
■xxx1.html(子ウィンドウを呼び出すHTML)←これが親ウィンドウになる
<html> <head> <script Language="JavaScript"><!-- function openWindow() { window.open("sub.html","sub","width=320,height=240"); } // --></script> </head> <body> <form name="frm1"> <input type="button" onclick="openWindow()"> <input type="text" name="box" value=""> </form> </body> </html>
■sub.thml(開かれる子ウィンドウ)
<html> <head> <script Language="JavaScript"><!-- function setData() { window.opener.frm1.box.value = document.getElementById("input").value; window.close(); } // --></script> </head> <body> <input type="text" id="input" value=""> <input type="button" onclick="setData()"> </body> </html>