- <!--parent.html -->
- <html>
- <head>
- <script type="text/javascript">
- var obj = {};
- function openwindow(url, name, iWidth, iHeight) {
- var url; //转向网页的地址;
- var name; //网页名称,可为空;
- var iWidth; //弹出窗口的宽度;
- var iHeight; //弹出窗口的高度;
- var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //获得窗口的垂直位置;
- var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; //获得窗口的水平位置;
- window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
- }
- function test() {
- alert("获取子页面的传回的参数: obj.result:" + obj.result);
- }
- </script>
- </head>
- <body>
- <form>
- <input type="button" value="打开窗口" onclick="openwindow('open.html', '', 400, 200)">
- </form>
- </body>
- </html>
- <!-- open.html -->
- <html>
- <head>
- <script>
- function closeWin() {
- // do something.
- window.opener.obj.result = 11; // 传递参数给父页面
- window.opener.test(); //回调副父页面的函数
- }
- </script>
- </head>
- <body>
- <form>
- <a href="#" onclick="javascript:closeWin();">操作完成后关闭窗口</a>
- </form>
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/2404201512430.html
来源: http://www.codesnippet.cn/detail/2404201512430.html