test40.htm:
<html><head><title></title>
<style type="text/css"></style>
<script language="javascript">
var child=window.open('test41.htm','_blank','width=20,height=15,left pixel value=0,titlebar=no,toolbar=yes,scrollbar=yes,status=yes,screenX pixel value=200,resizable=yes,location:yes');
function closeChild(){
if(!child.close()){
child.close();}
}
var dir=1;
var space_num=0;
function scroll(){
var str_space="";
if(space_num>225)
space_num=0;
space_num+=1*dir;
for(var i=0;i<space_num;i++)
{str_space+=" ";
}
window.status=str_space+"www.it315.org";}
</script>
</head>
<body onunload="closeChild()" onload="setInterval('scroll()',100)">
</body>
</html>
test41.htm:
<html><head><title></title>
<style type='text/css'></style>
<script language="javascript">
window.setTimeout("window.close()",7000);
//resizeTo(screen.availWidth,screen.availHeight);
var interval=setInterval("grow()",100);
function grow()
{window.resizeBy(10,10);}
window.status="www.jieti365.com";
var a=0;
function checkInterval(){
if(a==0)
{
clearInterval(interval);
a=1;}
else
{
interval.setInterval;
a=0;}
}
</script>
</head>
<body >
<p onclick="checkInterval()">70s后窗口关闭!点击这里窗口不再扩大!</p>
</body>
</html>
注意到子页面点击p标签可以停止启动setInterval函数,现在当第3次点击时不再有效果,
还有注意到我设置的变量interval,如果重启函数时直接为
function checkinterval{
if(a==0)
{
clearInterval(interval);
a=1;}
else
{
interval;//这里是不行的,那如果通过调用这个interval变量呢
a=0;}
}
<html><head><title></title>
<style type="text/css"></style>
<script language="javascript">
var child=window.open('test41.htm','_blank','width=20,height=15,left pixel value=0,titlebar=no,toolbar=yes,scrollbar=yes,status=yes,screenX pixel value=200,resizable=yes,location:yes');
function closeChild(){
if(!child.close()){
child.close();}
}
var dir=1;
var space_num=0;
function scroll(){
var str_space="";
if(space_num>225)
space_num=0;
space_num+=1*dir;
for(var i=0;i<space_num;i++)
{str_space+=" ";
}
window.status=str_space+"www.it315.org";}
</script>
</head>
<body onunload="closeChild()" onload="setInterval('scroll()',100)">
</body>
</html>
test41.htm:
<html><head><title></title>
<style type='text/css'></style>
<script language="javascript">
window.setTimeout("window.close()",7000);
//resizeTo(screen.availWidth,screen.availHeight);
var interval=setInterval("grow()",100);
function grow()
{window.resizeBy(10,10);}
window.status="www.jieti365.com";
var a=0;
function checkInterval(){
if(a==0)
{
clearInterval(interval);
a=1;}
else
{
interval.setInterval;
a=0;}
}
</script>
</head>
<body >
<p onclick="checkInterval()">70s后窗口关闭!点击这里窗口不再扩大!</p>
</body>
</html>
注意到子页面点击p标签可以停止启动setInterval函数,现在当第3次点击时不再有效果,
还有注意到我设置的变量interval,如果重启函数时直接为
function checkinterval{
if(a==0)
{
clearInterval(interval);
a=1;}
else
{
interval;//这里是不行的,那如果通过调用这个interval变量呢
a=0;}
}
<style type='text/css'></style>
<script language="javascript">
window.setTimeout("window.close()",7000);
//resizeTo(screen.availWidth,screen.availHeight);
function grow()
{window.resizeBy(10,10);}
window.status="www.jieti365.com";
var a=0;
function checkInterval()
{
if(a==0)
{var interval=setInterval("grow()",100);a=1;}
else
{clearInterval(interval); a=0;}
}
</script>
</head>
<body >
<p onclick="checkInterval()">70s后窗口关闭!点击这里窗口不再扩大!</p>
</body>
</html>
这样应该没什么问题了,还是运行不了
之前的问题我想明白了,clertInterval清除interval以后就没办法再调用interval
,所以循环设置新interval,但是这次运行不了
{
if(a==0)
{interval=setInterval("grow()",100);a=1;}
else
{clearInterval(interval); a=0;}
}
去掉 var,interval 是全局滴!