javascript怎么关闭浏览器

藏色散人
藏色散人 原创
2023-01-05 16:11:44 7203浏览

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怎么关闭浏览器的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。