JS判断浏览器
2021-03-15 14:29
标签:object bsp agent ever pat use amp test return JS判断浏览器 标签:object bsp agent ever pat use amp test return 原文地址:https://www.cnblogs.com/liujianshe1990-/p/12794955.html 1 //判断是否是IE
2 function isIEs() {
3 if (!!window.ActiveXObject || "ActiveXObject" in window)
4 return true;
5 else
6 return false;
7 }
8 function myBrowser() {
9 var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
10 var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
11 var isIE = userAgent.indexOf("compatible") > -1
12 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
13 var isEdge = userAgent.indexOf("Edge") > -1; //判断是否IE的Edge浏览器
14 var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
15 var isSafari = userAgent.indexOf("Safari") > -1
16 && userAgent.indexOf("Chrome") == -1; //判断是否Safari浏览器
17 var isChrome = userAgent.indexOf("Chrome") > -1
18 && userAgent.indexOf("Safari") > -1; //判断Chrome浏览器
19
20 if (isIEs()) {
21 if (isIE) {
22 var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
23 reIE.test(userAgent);
24 var fIEVersion = parseFloat(RegExp["$1"]);
25 if (fIEVersion == 7) {
26 return "IE7";
27 } else if (fIEVersion == 8) {
28 return "IE8";
29 } else if (fIEVersion == 9) {
30 return "IE9";
31 } else if (fIEVersion == 10) {
32 return "IE10";
33 } else {
34 return "0";
35 }//IE版本过低
36 return "IE";
37 } else {
38 if (!window.ActiveXObject && "ActiveXObject" in window) {
39 return "IE11";
40 }
41 }
42
43 }
44
45 if (isOpera) {
46 return "Opera";
47 }
48 if (isEdge) {
49 return "Edge";
50 }
51 if (isFF) {
52 return "FF";
53 }
54 if (isSafari) {
55 return "Safari";
56 }
57 if (isChrome) {
58 return "Chrome";
59 }
60
61 }