console.log(navigator.userAgentData);这个可以看浏览器的品牌
function isChromeUserBrowser(){
var browserName=navigator.userAgent.toLowerCase();
if(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName)&&navigator.userAgentData&&navigator.userAgentData.brands&&JSON.stringify(navigator.userAgentData.brands).indexOf("Google Chrome") >-1){
return true;
}else{
return false;
}
}console.log(isChromeUserBrowser());
有的浏览器会不支持这个属性,会返回undefined
2.navigator.userAgent是获取浏览器信息,userAgent.match是判断浏览器版本
getBrowser() {
var UserAgent = navigator.userAgent.toLowerCase();
var browser = null;
var browserArray = {
IE: window.ActiveXObject || "ActiveXObject" in window, // IE
Chrome:
UserAgent.indexOf("chrome") > -1 && UserAgent.indexOf("safari&