1. 程式人生 > >區分瀏覽器類型

區分瀏覽器類型

color exp isf navi amp avi urn row sop

How to detect Safari, Chrome, IE, Firefox and Opera browser?

Demo: https://jsfiddle.net/311aLtkz/

 1 // Opera 8.0+
 2 var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(‘ OPR/‘) >= 0;
 3 
 4 // Firefox 1.0+
 5 var isFirefox = typeof InstallTrigger !== ‘undefined‘;
6 7 // Safari 3.0+ "[object HTMLElementConstructor]" 8 var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window[‘safari‘] || safari.pushNotification); 9 10 // Internet Explorer 6-11 11 var isIE = /*@cc_on!@*/false || !!document.documentMode;
12 13 // Edge 20+ 14 var isEdge = !isIE && !!window.StyleMedia; 15 16 // Chrome 1+ 17 var isChrome = !!window.chrome && !!window.chrome.webstore; 18 19 // Blink engine detection 20 var isBlink = (isChrome || isOpera) && !!window.CSS;

區分瀏覽器類型