<!--------------------------html代码-------------------------->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>windowOpen</title>
<script type="text/javascript" src="case.js"></script>
</head>
<body>
<a href="javascript:void(null)" onclick="openWin()">点击弹出新窗口</a>
</body>
</html>
<!-----------------------javascript代码---------------------->
var win;
function openWin(){
var width=400;
var height=300;
var hcenter=(screen.width-width)/2;
var vcenter=(screen.height-height-50)/2;
var name="open"
var appearance="width="+width+",height="+height+",left="+hcenter+",top="+vcenter;
win=window.open("",name,appearance);
win.document.write("这是脚本open()函数打开的新窗口!")
win.setTimeout("win.close()",2000);
//win.setTimeout("self.close()",2000);
//window.setTimeout("win.close()",2000);
//window.setTimeout("self.close()",2000);
}
//window.setTimeout("win.close()",2000);
问题一:在浏览器中测试,得到如下结果,为什么win和self不是同一个窗口对象的引用?
win.setTimeout("win.close()",2000); //ff,IE11中均无效,新窗口不会定时关闭
win.setTimeout("self.close()",2000); //ff,IE11中均有效,新窗口会定时关闭
问题二:以下两行代码有不同的结果,为什么window调用setTimeout()却能对win起作用?
window.setTimeout("win.close()",2000); //ff,IE11中均有效
window.setTimeout("self.close()",2000);//在IE11中有效,但关闭的不是新窗口,ff中无效
问题三:在函数openWin()之外,
window.setTimeout("win.close()",2000);
这行代码也可以定时关闭新窗口,但是第一次定时关闭窗口后,
接下来打开的新窗口都不会定时关闭,除非先刷新再打开新窗
口,这也不知为何?