js判断各种浏览器

开发时遇到需要判断国内不同浏览器的问题,故想从网上查找,但最后也没有找到一种通用的解决方法。判断浏览器大体有两种方法:1、根据userAgent判断,但是userAgent可以被用户进行修改,并且随着浏览器的更新,其相应的userAgent也有可能被修改,所以不宜作为判断的依据。2、根据各种浏览器特有的对象的一些属性判断。但对于判断国内的浏览器来说没啥用。

1 根据userAgent判断

var explorer = window.navigator.userAgent.toLowerCase();

    if (explorer.indexOf("qqbrowser") >= 0 || explorer.indexOf("qq") >= 0) {    //QQ
    } else if (explorer.indexOf("safari") >= 0 && explorer.indexOf("metasr") >= 0) {    //搜狗
    } else if (!!window.ActiveXObject || "ActiveXObject" in window) {//IE
        /* if (!window.XMLHttpRequest) {
            return myexplorer = "IE6";
        } else if (window.XMLHttpRequest && !document.documentMode) {
            return myexplorer = "IE7";
        } else if (!-[ 1, ] && document.documentMode
                && !("msDoNotTrack" in window.navigator)) {
            return myexplorer = "IE8";
        } else {//IE9 10 11
            var hasStrictMode = (function() {
                "use strict";
                return this === undefined;
            }());
            if (hasStrictMode) {
                if (!!window.attachEvent) {
                    return myexplorer = "IE10";
                } else {
                    return myexplorer = "IE11";
                }
            } else {
                return myexplorer = "IE9";
            }
        } */
    } else {//非IE
        if (explorer.indexOf("lbbrowser") >= 0) {   //猎豹
        } else if(explorer.indexOf("ubrowser") >= 0 || explorer.indexOf("ucbrowser") >= 0){ //uc
        } else if (explorer.indexOf("opera") >= 0 || explorer.indexOf("opr") >= 0) {    //欧朋
        } else if (explorer.indexOf("firefox") >= 0) {  //火狐
            return true;
        } else if (explorer.indexOf("maxthon") >= 0) {  //遨游
        } else if (explorer.indexOf("chrome") >= 0) {   //谷歌(或360伪装)
            return true;
        }else if (explorer.indexOf("theworld") >= 0) {  //世界之窗
        } else if (explorer.indexOf("safari") >= 0) {   //苹果
        } else {    //其他
        }
    }

2 相关判断浏览器的链接

http://blog.sina.com.cn/s/blog_64589b110101bzvh.html

http://www.cnblogs.com/dreamhome/archive/2013/01/27/2878532.html

http://www.cnblogs.com/longze/archive/2013/06/07/3124354.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值