标签:字符 谷歌 firefox agent inf type check use alert
window.onload = function(){
//测试媒体类型 谷歌和360差别就在这里
let checkMimeType = function(option, value){
let mimeTypes = navigator.mimeTypes;
for (let mt in mimeTypes) {
if (mimeTypes[mt][option] == value) {
return true;
}
}
return false;
}
let judge = function(){
let agent = navigator.userAgent;
// alert(agent);
let ie = /Trident\/(\d+\.)+\d+/ig;
let ff = /Firefox\/(\d+\.)+\d+/ig;
let chrome = /Chrome\/(\d+\.)+\d+/ig;//谷歌,360
let saf = /Safari\/(\d+\.)+\d+/ig;//苹果
let opr = /OPR\/(\d+\.)+\d+/ig;
let is360 = checkMimeType("type", "application/vnd.chromium.remoting-viewer");
//如果存在Firefox,就返回与之匹配的正则
if(agent.match(ff)){
return "火狐--" + agent.match(ff);
}else if(agent.match(ie)){
return "IE--" + agent.match(ie);
}else if(agent.match(saf) && !agent.match(chrome)){//找到苹果,但找不到谷歌
return "苹果--" + agent.match(saf) ;
}else if(agent.match(chrome)){//有谷歌
if(agent.match(opr)){//判断是否是欧鹏
return "欧鹏--" + agent.match(opr);
}else if(is360){//判断是否是360
return "360--" + agent.match(chrome);
}
return "谷歌--" + agent.match(chrome);
}
}
let browser = judge();
alert(browser);
//只看版本
// let verinfo = (browser+"").replace(/[^\d.]/ig,""); //用空去替代返回的字符串出现的非数字
// alert(verinfo);
}
标签:字符 谷歌 firefox agent inf type check use alert
原文地址:http://www.cnblogs.com/zjzy/p/7503346.html