区分浏览器类型

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了区分浏览器类型相关的知识,希望对你有一定的参考价值。

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 = /*@[email protected]*/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;

 

以上是关于区分浏览器类型的主要内容,如果未能解决你的问题,请参考以下文章

Doctype作用?严格模式与混杂模式如何区分?它们有何差异?

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

如何区分两个“onpause”事件 - 由单击“暂停”按钮引起,以及由到达媒体片段末尾引起?

区分不同类型的 beforeunload 事件

在代码片段中包含类型转换

6.26