class BrowserDetector{
constructor(){
this.isIE_Gte6Lte10=/*@cc_on!@*/false;
this.isIE_Gte7Lte11=!!document.documentMode;
this.isEdge_Gte20=!!window.StyleMedia;
this.isFirefox_Gte1=typeof InstallTrigger!=="undefined";
this.isChrome_Gte1=!!window.chrome && !!window,chrome.webstore;
this.isSafari_Gte3Lte9_1=/constructor/i.test(window.Element);
this.isSafari_Gte7_1=
(({pushNotification={}}={})=>
pushNotification.toString()=='[object SafariRemoteNotification]'
)(window.safari);
}
isIE(){
return this.isIE_Gte6Lte10 || this.isIE_Gte7Lte11;
}
isEdge(){
return this.isEdge_Gte20 && !this.isIE();
}
isFirefox(){
return this.isFirefox_Gte1;
}
isChrome(){
return this.isChrome_Gte1;
}
isSafari(){
return this.isSafari_Gte3Lte9_1 || this.isSafari_Gte7_1;
}
}
//获取类的所有原型方法
let method=Object.getOwnPropertyNames(BrowserDetector.prototype);
method.forEach(name=>{
const prop=new BrowserDetector();//创建实例
if(name!=='constructor')//排除构造函数
{
if(prop[name]())
{
console.info(name);
}
}
})
javascript识别浏览器类型
最新推荐文章于 2024-10-06 23:41:23 发布