1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | const detectBrowser = function(ua) {
|
10 | var tem;
|
11 | var M =
|
12 | ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) ||
|
13 | [];
|
14 | if (/trident/i.test(M[1])) {
|
15 | tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
|
16 | return "IE " + (tem[1] || "");
|
17 | }
|
18 | if (M[1] === "Chrome") {
|
19 | tem = ua.match(/\b(OPR|Edge)\/(\d+)/);
|
20 | if (tem != null)
|
21 | return tem
|
22 | .slice(1)
|
23 | .join(" ")
|
24 | .replace("OPR", "Opera");
|
25 | }
|
26 | M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, "-?"];
|
27 | if ((tem = ua.match(/version\/(\d+)/i)) != null) M.splice(1, 1, tem[1]);
|
28 | return M.join("-");
|
29 | };
|
30 |
|
31 | export default detectBrowser;
|