您的位置:首页 > 技术中心 > 前端框架 >

javascript怎么关闭浏览器

时间:2021-04-27 10:01

javascript关闭浏览器的方法:1、通过“ function CloseWebPage(){...}”方法实现关闭浏览器网页;2、通过“open(location, '_self').close();”方法关闭浏览器网页。

本文操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。

js实现关闭浏览器

兼容所有浏览器网页关闭方法

<button  id="exitSystem" onclick="CloseWebPage()">关闭</button>
        <script>
            function CloseWebPage() {
                if (navigator.userAgent.indexOf("MSIE") > 0) {
                    if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {
                        window.opener = null; window.close();
                    }
                    else {
                        window.open('', '_top'); window.top.close();
                    }
                }
                else if (navigator.userAgent.indexOf("Firefox") > 0) {
                    window.location.href = 'about:blank '; //火狐默认状态非window.open的页面window.close是无效的
                    //window.history.go(-2);
                }
                else {
                    window.opener = null;
                    window.open('', '_self', '');
                    window.close();
                }
            }
        </script>

第二种方法,也可以针对谷歌浏览器的

<button style="margin-left: 500px" onclick="CloseWebPage()">退出</button>
<script>
    function CloseWebPage() {
        open(location, '_self').close();
    }
</script>

【推荐学习:javascript高级教程

以上就是javascript怎么关闭浏览器的详细内容,更多请关注www.gxlsystem.com其它相关文章!

本类排行

今日推荐

热门手游