js区分360和谷歌浏览器(火狐、搜狗等)


首先区分火狐和谷歌浏览器,根据百度经验可以解决:

针对火狐浏览器的CSS Hack:

@-moz-document url-prefix() {    .selector {        attribute: value;    }}

针对webkit内核及Opera浏览器的CSS Hack:

@media all and (min-width:0){    .selector {        attribute: value;/*for webkit and opera*/    }}

从这个样式我们只能把webkit内核的浏览器和Opera浏览器从其它浏览器中区分出来,但并不能区分它们俩,因此我们还需要在上面样式的基础上再加一个样式:

@media screen and (-webkit-min-device-pixel-ratio:0) {    .selector {        attribute: valueForWebKit;/*only for webkit*/    }}


转载自:https://jingyan.baidu.com/article/fdffd1f8383c28f3e98ca13e.html



但是360和谷歌内核一样,但是有一处样式在页面渲染出的效果就是不一样,于是只好用js判断然后给出不同样式。

function checkBrowser(){
var ua = navigator.userAgent.toLocaleLowerCase();
var browserType=null;
    if (ua.match(/msie/) != null || ua.match(/trident/) != null) {
       browserType = "IE";
       browserVersion = ua.match(/msie ([\d.]+)/) != null ? ua.match(/msie ([\d.]+)/)[1] : ua.match(/rv:([\d.]+)/)[1];
} else if (ua.match(/firefox/) != null) {
       browserType = "火狐";
}else if (ua.match(/ubrowser/) != null) {
       browserType = "UC";
}else if (ua.match(/opera/) != null) {
       browserType = "欧朋";
} else if (ua.match(/bidubrowser/) != null) {
       browserType = "百度";  
}else if (ua.match(/metasr/) != null) {
       browserType = "搜狗";  
}else if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null) {
       browserType = "QQ";
}else if (ua.match(/maxthon/) != null) {
       browserType = "遨游";
}else if (ua.match(/chrome/) != null) {
var is360 = _mime("type", "application/vnd.chromium.remoting-viewer");
function _mime(option, value) {
            var mimeTypes = navigator.mimeTypes;
            for (var mt in mimeTypes) {
            if (mimeTypes[mt][option] == value) {
                   return true;
              }
            }
            return false;
        }
if(is360){               
browserType = '360';  
             }else{  
            browserType = "谷歌";  
             }  
       
}else if (ua.match(/safari/) != null) {
       browserType = "Safari";
}
return browserType;
}

转载自:http://blog.csdn.net/github_38806262/article/details/72627871


猜你喜欢

转载自blog.csdn.net/m0_37935476/article/details/78110177