<!--主页面的代码-->
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script type="text/javascript" src="../../commonJS/jquery.js"></script> <script> </script> </head> <body> <div style="140px; height:60px; position:relative;display:inline-block;background-color: red; margin-right:20px;display:inline-block;cursor: pointer;" id="addMatchSchedule"> </div> </body> </html> <script> $("#addMatchSchedule").click(function() {alert("a"); window.open('child.html',"新增","width=500,height=480,screenX=400,screenY=100"); } ); //子页面调用的函数 window.BBBB = function(){ alert(112); } </script>
<!--子页面-->
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <script src="../../commonJS/jquery.js"></script> <body> <a class="btn btn-small btn-info" onclick="addSchduleItem();" title="确定" >确定</a> </body> </html> <script> //确定关闭页面 function addSchduleItem() { if (window.opener != null && !window.opener.closed) { window.opener.BBBB();//调用主页面的函数 } window.close(true); } </script>
一句话概括思路:在父窗口中打开子窗口,在子窗口中调用父窗口的方法
核心方法:window.open() (方法介绍在本文尾部)
核心概念:window.opener (方法介绍在本文尾部)
window.open()简介(以具体情况为例):
window.open('page.html', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no') //该句写成一行代码
参数解释:
window.open 弹出新窗口的命令;
'page.html' 弹出窗口的文件名;
'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空''代替;
height=100 窗口高度;
width=400 窗口宽度;
top=0 窗口距离屏幕上方的象素值;
left=0 窗口距离屏幕左侧的象素值;
toolbar=no 是否显示工具栏,yes为显示;
menubar,scrollbars 表示菜单栏和滚动栏。
resizable=no 是否允许改变窗口大小,yes为允许;
location=no 是否显示地址栏,yes为允许;
status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
window.opener 简介
window.opener 实际上就是通过window.open打开的子窗体的父窗体