1. 程式人生 > >js 瀏覽器判斷

js 瀏覽器判斷

js 瀏覽器判斷

其他鏈接:https://segmentfault.com/a/1190000004493157


function browerCheck(){

var userAgent = window.navigator.userAgent;

var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判斷是否IE<11瀏覽器

var is360 = userAgent.indexOf('360'); // 判斷是否為360瀏覽器

var isSougou = userAgent.toLowerCase().indexOf('se 2.x')>-1; // 判斷是否為搜狗瀏覽器

var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;

var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判斷是否IE<11瀏覽器

var isGoogle = userAgent.indexOf("Chrome") > -1; //判斷是否IE<11瀏覽器

var rstStatus = false;

//IE瀏覽器

if ( !isIE11 ) {

if( isIE ) {

var version = userAgent.match(/MSIE ([\d.]+)/)[1];

if( version < 11) {

rstStatus = true;

modalInfo("當前IE瀏覽器版本低於IE11");

}

} else if( !isGoogle ) {

rstStatus = true;

modalInfo("當前瀏覽器非IE瀏覽器或Google瀏覽器");

}

}

if(is360 || isSougou) {

rstStatus = true;

modalInfo("當前瀏覽器非IE瀏覽器或Google瀏覽器");

}

return rstStatus;

};


// UC:navigator.userAgent.indexOf('UCBrowser') > -1
//是否QQ
isQQ: function() {
var ua = navigator.userAgent.toLowerCase();
return !!ua.match(/mqqbrowser|qzone|qqbrowser/i);
}


js 瀏覽器判斷