javascript怎么关闭浏览器


本文摘自PHP中文网,作者藏色散人,侵删。

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

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

js实现关闭浏览器

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

<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>

阅读剩余部分

相关阅读 >>

如何使用css设计出一个表单页面(附示例)

利用jssdk在网页中获取地理位置

实例详解javascript中split字符串分割函数

javascript怎么停止函数执行

object.fromentries和object.entries的使用

javascript要什么基础?

深入了解javascript中的null

html页面自动清理js、css文件的缓存(自动添加版本号)_html/xhtml_网页制作

你不太了解的json

javascript失去焦点如何设置

更多相关阅读请进入《javascript》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...