父子窗口之间传值是经常遇到的问题
parent.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
- <title>子窗口传值给父窗口</title>
- <script language="JavaScript" type="text/javascript">
- function openWin(u, w, h) {
- var l = (screen.width - w) / 2;
- var t = (screen.height - h) / 2;
- var s = 'width=' + w + ', height=' + h + ', top=' + t + ', left=' + l;
- s += ', toolbar=no, scrollbars=no, menubar=no, location=no, resizable=no';
- open(u, 'oWin', s);
- }
- function openIt(){
- window.open("page2.htm",400,300);
- }
- </script>
- </head>
- <body>
- <input type="text" id="text1" />
- <input type="button" value="Go" onclick="openIt()" />
- </body>
- </html>
child.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
- <title>子窗口传值给父窗口</title>
- <script language="JavaScript" type="text/javascript">
- function goback(obj){
- window.opener.document.getElementById("text1").value = obj.value;
- window.close();
- }
- </script>
- </head>
- <body>
- <div><input type="button" value="sucre" onclick="goback(this)" /></div>
- <div><input type="button" value="javaeye" onclick="goback(this)" /></div>
- </body>
- </html>