精准判断是360、IE和其他浏览器

function myexplorer(){
var explorer = window.navigator.userAgent;
if (!!window.ActiveXObject || "ActiveXObject" in window){//IE
if (!window.XMLHttpRequest){
return myexplorer="IE"; //IE6
}else if (window.XMLHttpRequest && !document.documentMode){
return myexplorer="IE"; //IE7
}else if (!-[1,] && document.documentMode && !("msDoNotTrack" in window.navigator)){
return myexplorer="IE"; //IE8
}else{//IE9 10 11
var hasStrictMode=(function(){
"use strict";
return this===undefined;
}());
if (hasStrictMode){
if (!!window.attachEvent){
return myexplorer="IE"; //IE10
}else{
return myexplorer="IE"; //IE11
}
}else{
return myexplorer="IE"; //IE9
}
}
}else{//非IE
//application/vnd.chromium.remoting-viewer 可能为360特有
var is360 = _mime("type", "application/vnd.chromium.remoting-viewer");

if (isChrome() && is360) {
return myexplorer= "360";
}else{
return myexplorer= "other"; //其他浏览器
}
}
}

var browser = myexplorer();
if(browser == "IE" || browser == "360"){
get_video_list();
}else{
alert("其他");
}

//检测是否是谷歌内核(可排除360及谷歌以外的浏览器)
function isChrome(){
var ua = navigator.userAgent.toLowerCase();

return ua.indexOf("chrome") > 1;
}
//测试mime
function _mime(option, value) {
var mimeTypes = navigator.mimeTypes;
if(mimeTypes){
for (var mt in mimeTypes) {
if (mimeTypes[mt][option] == value) {
return true;
}
}
return false;
}
}



方法二

$.browser = function () {
    var userAgent = navigator.userAgent;
    var isOpera = userAgent.indexOf("Opera") > -1;
    if (isOpera) {
       return "Opera"
    };
    if (userAgent.indexOf("Firefox") > -1) {
      return "Firefox";
    }
   if (userAgent.indexOf("Chrome") > -1) {
       if (window.navigator.webkitPersistentStorage.toString().indexOf('DeprecatedStorageQuota') > -1) {
           return "Chrome";
        } else {
             return "360";
       }
    }
    if (userAgent.indexOf("Safari") > -1) {
      return "Safari";
    }
      if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
          return "IE";
     };
}

posted @ 2019-04-18 09:53  web前端参天大圣  阅读(756)  评论(0编辑  收藏  举报