js获取浏览器类型

getBrowser = () => {
            const userAgent = navigator.userAgent.toLowerCase();
            let browser = null;
            (userAgent.indexOf('chrome') > -1 && userAgent.indexOf('safari') > -1) ? browser = 'chrome'
            : (userAgent.indexOf('firefox') > -1) ? browser = 'firefox'
            : (userAgent.indexOf('safari') > -1 && userAgent.indexOf('chrome') === -1) ? browser = 'safari'
            : (userAgent.indexOf('opera') > -1) ? browser = 'opera'
            : (userAgent.indexOf('compatible') > -1 && userAgent.indexOf('msie') > -1 &&
            userAgent.indexOf('opera') <= -1) ? browser = 'ie'
            : (userAgent.indexOf('edge') > -1) ? browser = 'edge' : browser = 0;
            return browser;
        }

相关推荐