freeethy

必须要全力以赴,才能看起来毫不费力。

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

使用js关闭浏览器,ios下的uc、360、qq有问题

    ```
    var u = navigator.userAgent
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    var isSafari = u.toLowerCase().indexOf('safari') != -1
    if(isiOS) {
        // ios的safari支持window.close,uc、360、qq浏览器不支持
        if(isSafari) {
            window.opener = null;
            window.open("","_self").close()
        }
        return
    }
    if (navigator.userAgent.indexOf("MSIE") > 0) { //close IE  
        if (u.indexOf("MSIE 6.0") > 0) {
            window.opener = null;
            window.close();
        } else {
            window.open('', '_top');
            window.top.close();
        }
    } else if (u.indexOf("Firefox") > 0) { //close firefox  
        window.location.href = 'about:blank';
    } else if (u.toLowerCase().indexOf("ucbrowser") > 0) {
        window.location.href = '';
        setTimeout(()=>{
            window.location.href = 'about:blank';
        },0)
    } else { //close chrome;It is effective when it is only one.  
        window.opener = null;
        window.open("","_self").close()
        window.location.href = 'about:blank';
    }
    ```
posted on 2017-12-12 16:43  freeethy  阅读(359)  评论(0编辑  收藏  举报