js 解析浏览器版本

/*!
 * Check browser
 * Author: zhugao
 * Date: 2013-7-23
 */

var domainBase = '';
 
var checkBrowser = {
    ua: navigator.userAgent,
    help: function () {
        location.href = domainBase + '/help/chrome';
    },
    goIndex: function () {
        location.href = domainBase + '/dashboard/index';
    },
    subtitleEnabled: function () {
        return "track" in document.createElement("track");
    },
    scopedEnabled: function () {
        return "scoped" in document.createElement("style");
    },
    isChrome: function () {
        if (this.ua.indexOf("Chrome") !== -1) return true;
        return false;
    },
    isIOS: function () {
        if (/(iPhone|iPad|iPod)/i.test(this.ua)) return true;
        return false;
    },
    isAndroid: function () {
        if (/Android/i.test(this.ua)) return true;
        return false;
    },
    isMac: function() {
        return navigator.platform.toUpperCase().indexOf('MAC') >= 0;
    },
    isSafari: function () {
        if (this.ua.indexOf("Safari") != -1) return true;
        return false;
    },
    isSougou: function () {
        if (navigator.userAgent.toLowerCase().indexOf('se 2.x') != -1) return true;
        return false;
    },
    is360: function () {
        if (this.subtitleEnabled() && this.scopedEnabled()) return true;
        return false;
    },

    // 检查所有页面
    checkAllPage: function () {

        if (this.isIOS() || this.isAndroid()) {
            return;
        }

        if (!this.isChrome()) {
            if ((this.isMac() || this.isIOS()) && this.isSafari()) {
                // 在IOS上使用safari
            } else {
                this.help();
            }
        } else {
            if (this.is360() || this.isSougou()) {
                // 360
                this.help();
            }
        }
    },

    // 检查chrome下载页面
    checkHelpPage: function () {
        if (this.isChrome()) {
            if (this.is360() || this.isSougou()) {
            } else {
                this.goIndex();
            }
        }
    }
};

var GLOBAL_CONFIG = GLOBAL_CONFIG,
    _global_config = GLOBAL_CONFIG || '';

if (_global_config) {
    // v1
    domainBase = window.BASE_URL.ROOT;
    if (!GLOBAL_CONFIG.isDownloadChromePage) {
        checkBrowser.checkAllPage();
    } else {
        checkBrowser.checkHelpPage();
    }
} else {
    // v2
    domainBase = window._global.url.base;
    checkBrowser.checkAllPage();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值