如何检测Safari、Chrome、IE、Firefox和Ope

2019-06-12  本文已影响0人  Panr

原文来自:原文出处

// Opera 8.0+

let isOpera =

    (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(" OPR/") >= 0;

// Firefox 1.0+

let isFirefox = typeof InstallTrigger !== "undefined";

// Safari 3.0+ "[object HTMLElementConstructor]"

let isSafari =

    /constructor/i.test(window.HTMLElement) ||

    (function(p) {

        return p.toString() === "[object SafariRemoteNotification]";

    })(!window["safari"] || (typeof safari !== "undefined" && safari.pushNotification));

// Internet Explorer 6-11

let  isIE = /*@cc_on!@*/ false || !!document.documentMode;

// Edge 20+

let isEdge = !isIE && !!window.StyleMedia;

// Chrome 1+

let isChrome =

    !isOpera && !isFirefox && !!navigator.userAgent.toLowerCase().match(/chrome/);

let supportDirectory = !!isFirefox || !!isChrome;

// Blink engine detection

let isBlink = (isChrome || isOpera) && !!window.CSS;

上一篇 下一篇

猜你喜欢

热点阅读