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;
        }
    原文作者:Snoopy
    原文地址: https://segmentfault.com/a/1190000018391113
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞