admin管理员组文章数量:1650787
众所周知,一般情况下,可以根据userAgent来判断浏览器类型,大多数浏览器都能这样判别,但比较坑的是,自某次事件后,360彻底赖上谷歌了,这一下坑了好多人,因为很多人都不知道如今还能用什么方法区分开它俩,小弟有幸偶然发现他俩一点点区别,下面附上js代码,虽然一堆if else 比较low,不过亲测后效果还是有的:
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;
}
本文标签: 浏览器
版权声明:本文标题:如何区分360浏览器和谷歌浏览器 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1729519850a1204418.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论