在做浏览器兼容的时候,要经常根据不同的浏览器展示页面,所以我参考了资料,总结了三个主流浏览器的判别方法:
function checkBrowserType() {
let Msie = /(msie\s|trident.*rv:)([\w.]+)/;
let Firefox = /(firefox)\/([\w.]+)/;
let Chrome = /(chrome)\/([\w.]+)/;
let agent = navigator.userAgent.toLowerCase();
let match = Msie.exec(agent);
if (match) {
this.browserType = BrowserType.IE;
}
match = Firefox.exec(agent);
if (match) {
this.browserType = BrowserType.Firefox;
}
match = Chrome.exec(agent);
if (match) {
this.browserType = BrowserType.Chrome;
}
}