判断浏览器版本

1.判断是否是IE浏览器版本
function IEVersion() {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器 var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器 var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1; if(isIE) { var reIE = new RegExp("MSIE (\\d+\\.\\d+);"); reIE.test(userAgent); var fIEVersion = parseFloat(RegExp["$1"]); if(fIEVersion == 7) { return 7; } else if(fIEVersion == 8) { return 8; } else if(fIEVersion == 9) { return 9; } else if(fIEVersion == 10) { return 10; } else { return 6;//IE版本<=7 } } else if(isEdge) { return 'edge';//edge } else if(isIE11) { return 11; //IE11 }else{ return -1;//不是ie浏览器 } if (isIE || isEdge ||isIE11) { Notify("由于兼容性问题,建议使用谷歌浏览器。", getNotifyPos(), "10000", "warning", "fa-exclamation-triangle", !0); return false; } }

2.全球和中国的主流浏览器

全球:Google、Firefox、IE、Safari、Edge、Opera
中国:Google、IE、QQ、2345、搜狗、火狐、猎豹、
移动: QQ、UC、360、百度、搜狗、猎豹、2345、谷歌、绿茶

  3.各大浏览器内核

(1)谷歌

原生谷歌:"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
封装谷歌(百度下载):
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"

(2)Firefox
 Mozilla/5.0 (Windows NT 6.1; WOW64; rv:59.0) Gecko/20100101 Firefox/59.0"

(3)IE、Eege

(4)Safari
"mozilla/5.0 (windows nt 6.1; wow64) applewebkit/534.57.2 (khtml, like gecko) version/5.1.7 safari/534.57.2"
version

(5)Opera
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36 OPR/52.0.2871.40"

(6)360
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"

IE11 模式
"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3; rv:11.0) like Gecko"

(7)QQ
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.4482.400 QQBrowser/9.7.13001.400"
QQBrowser

(8)2345 两个模式(内核):Chrome、IE11
"mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/56.0.2924.90 safari/537.36 2345explorer/9.2.1.17116"
2345explorer

(9)搜狗
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0"
navigator.userAgent.toLowerCase().indexOf('se 2.x')>-1 ? true : false

(10)UC
"mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/55.0.2883.87 ubrowser/6.2.3964.2 safari/537.36"
ubrowser
(11)百度
"mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/47.0.2526.106 bidubrowser/8.7 safari/537.36"
bidubrowser

(12)猎豹
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER"

5.判断浏览器内核

      function IEVersion() {
            var isTrue = true;
            var userAgent = window.navigator.userAgent; //取得浏览器的userAgent字符串  
            var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器  
            var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
            var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
            var isChrome = userAgent.toLowerCase().indexOf("chrome") !== -1;
            var isWin64 = userAgent.toLowerCase().indexOf("win64") !== -1;
            var isJs360 = userAgent.toLowerCase().indexOf('applewebkit') == -1;
            var isQQ = userAgent.toLowerCase().indexOf('qqbrowser') !== -1;
            var isSouGou = userAgent.toLowerCase().indexOf('se 2.x') !== -1;
            var isOpera = userAgent.toLowerCase().indexOf('opr') !== -1;
            var isBaidu = userAgent.toLowerCase().indexOf('bidubrowser') !== -1;
            var isUC = userAgent.toLowerCase().indexOf('ubrowser') !== -1;
            var is2345 = userAgent.toLowerCase().indexOf('2345explorer') !== -1;
            var isSafari = userAgent.toLowerCase().indexOf('version') !== -1;
            var isSaVersion = userAgent.toLowerCase().indexOf('version') !== -1;
       

        var isFirefox= userAgent.toLowerCase().indexOf('firefox') !== -1;
        if (isIE || isIE11 || isEdge||(isChrome && isJs360) || isQQ || isSouGou || isOpera || isUC || isBaidu || is2345 || (isSafari &&

isSaVersion)||isFirefox) {
                  Notify("由于兼容性问题,建议使用谷歌浏览器。", getNotifyPos(), "10000", "warning", "fa-exclamation-triangle", !0)
                  return false;
              }

        }
 注:360浏览器经过各个版本的优化,内核内容已经和谷歌浏览器一样无法分辨了,若有其他方式,请共享一下,谢谢!!

 转载 https://www.cnblogs.com/XCWebLTE/archive/2017/06/15/7017338.html

posted on 2018-03-23 09:42  风端的爱  阅读(651)  评论(0编辑  收藏  举报

导航