下面的例子将弹出窗口的输入值传递给父窗口显示出来。
<html> <body> <script type="text/javascript"> myWindow=window.open('2.html','MyName','width=300,height=200') </script> </body> </html>
<html> <body> <script type="text/javascript"> function getInput(){ var input_char = document.getElementById("input_char").value; window.opener.document.write(input_char); } </script> </body> <input id="input_char" type="text" value="输入些文字" /> <button onclick="getInput()">点击我试试</button> </html>
运行1.html(设置允许浏览器弹出窗口),在弹出窗口的文字输入框输入文字,点击按钮,1.html 页面会打印出输入的文字。