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怎么关闭浏览器的详细内容,更多请关注其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。