若干秒后不操作自动关闭窗口

<!DOCTYPE >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>若干秒后不操作自动关闭窗口</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript">
        var willclose = true; //定义一个是否关闭的全局变量
        //单击网页
        function clickBody() {
            willclose = false;  //单击网页后把变量设置为false
        }
        //setInterval()函数可以用来计时和进行重复操作
        setInterval(function () {
            if (willclose) {//判断是否需要关闭
                window.close();
            }
            else {
                willclose = true;
            }
        }, 1000);
    </script>
</head>
<body style=" text-align:center" onclick="clickBody">
    <!--如果用户10秒钟不单击网页本窗口将自动关闭-->
</body>
</html>

 

posted @ 2017-11-28 21:38  转身,便是天涯  阅读(247)  评论(0编辑  收藏  举报