在chrome浏览器里使用必须是在项目里面
main.html代码
<!DOCTYPE html>
<html>
<head>
<title>main</title>
<meta charset="utf-8">
<script language="javascript" type="text/javascript">
var wd;
var winTimer;//计时器变量, 监听窗口关闭
function openWindow() {
wd = window.open("child.html",null," height=300,width=450, Left=300px,Top=20px, menubar=no,titlebar=no,scrollbar=no,toolbar=no, status=no,location=no");
if (wd){
window.wd.focus();//判断窗口是否打开,如果打开,窗口前置
winTimer=window.setInterval("wisclosed()",500);
}
}
function wisclosed(){
if(wd.closed){
alert(window.returnVaule);//子窗体返回值
//这里可以做赋值操作
window.clearInterval(winTimer);
}
}
</script>
</head>
<body>
<input type="button" id="btnShow" οnclick="openWindow();" value="显示子窗口"/>
</body>
</html>
child.html代码
<!DOCTYPE html>
<html>
<head>
<title>child</title>
<meta charset="utf-8">
<script language="javascript" type="text/javascript">
function doclose() {
window.opener.window.returnVaule="ok";
parent.window.close();
}
</script>
</head>
<body>
<input type="button" id="btnSelect" οnclick="doclose();" value="关闭"/>
</body>
</html>