主题:window对象的open方法
写了如下代码,作用是当打开该网页文件5秒后,在新窗口中打开一个名为infomation.html的网页,并且当主窗口关闭时,此窗口也跟着关闭。
<script language=javascript>
function openNew()
{
var child=window.open("information.html","_blank","top=10,left=10,width=200,height=200,toolbar=no");
}
setTimeout("openNew()",5000);
function closeChild()
{
if (!child.closed)
{
child.close();
}
}
</script>
<body onunload="closeChild()">
</body>
可是运行的结果是,当主窗口关闭时,子窗口并不关闭。将代码改写成如下的形式;
<script language=javascript>
var child=window.open("information.html","_blank","top=10,left=10,width=200,height=200,toolbar=no");
function closeChild()
{
if (!child.closed)
{
child.close();
}
}
</script>
<body onunload="closeChild()">
</body>
就可以达到预想的效果。不知道前面的代码哪里出了问题。
<script language=javascript>
function openNew()
{
var child=window.open("information.html","_blank","top=10,left=10,width=200,height=200,toolbar=no");
}
setTimeout("openNew()",5000);
function closeChild()
{
if (!child.closed)
{
child.close();
}
}
</script>
<body onunload="closeChild()">
</body>
可是运行的结果是,当主窗口关闭时,子窗口并不关闭。将代码改写成如下的形式;
<script language=javascript>
var child=window.open("information.html","_blank","top=10,left=10,width=200,height=200,toolbar=no");
function closeChild()
{
if (!child.closed)
{
child.close();
}
}
</script>
<body onunload="closeChild()">
</body>
就可以达到预想的效果。不知道前面的代码哪里出了问题。