关于两种定时器的打开关闭和窗口打开关闭

这一章主要讲讲定时器的打开和关闭以及窗口的打开和关闭。
定时器主要分为两种。
其一,setTimeout,在指定时间只执行一次;

<script>  
    //定时器 异步运行  
    function hello(){  
       alert("hello");  
    }  
    //使用方法名字执行方法  
    var t1 = window.setTimeout(hello,1000);  
    var t2 = window.setTimeout("hello()",3000);//使用字符串执行方法  
    window.clearTimeout(t1);//去掉定时器  
</script>   

其二,setInterval,在指定时间循环执行。

<script>   
     //实时刷新时间单位为毫秒  
    var timer1 = window.setInterval('refreshQuery()',8000);         
    window.clearInterval(timer1);//清除定时器
</script>   

关于窗口的打开有两种方式 :
其一,是链接的跳转,不打开新页面: <a href="a.html"></a> ,相当于 window.location.href = "a.html";
其二,是新窗口打开<a href="a.html" target="_blank"></a> ,相当于window.open("a.html");

关于window.open()的窗口关闭使用window.close()

var myWin=window.open('http://www.a.com'); //将新打的窗口对象,存储在变量myWin中
myWin.close()

关于window.open的参数,详情如下:

window.open('http://www.a.com','_blank','width=300,height=200,menubar=no,toolbar=no, status=no,scrollbars=yes')

猜你喜欢

转载自blog.csdn.net/diaoweixiao/article/details/80705990