Agent.js
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class Agent {
/**
* 判断是否是Android浏览器
*/
static isAndroid() {
return navigator.userAgent.indexOf('Android') > -1;
}
/**
* 判断是否是iOS浏览器
*/
static isIOS() {
return !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
}
/**
* 判断是否是微信浏览器
*/
static isWechat() {
return /micromessenger/.test(navigator.userAgent.toLowerCase());
}
/**
* 判断是否是QQ内置浏览器
*/
static isQQ() {
return navigator.userAgent.toLowerCase()
.indexOf(' qq') > -1;
}
/**
* 判断是否是android App
*/
static isAndroidApp() {
return /kolapp\/.*-android/.test(navigator.userAgent.toLowerCase());
}
/**
* 判断是否是iOS App
*/
static isIOSApp() {
return /kolapp\/.*-ios/.test(navigator.userAgent.toLowerCase());
}
/**
* 获取android App版本号
*/
static getAndroidVersion() {
// return /(?<=plusapp\/)(.*)(?=-android)/.exec(navigator.userAgent.toLowerCase());
const agentVersions = navigator.userAgent.toLowerCase()
.split('-android')[0];
const version = agentVersions.toLowerCase()
.split('kolapp/')[1];
return version;
}
/**
* 获取ios App版本号
*/
static getIOSVersion() {
const agentVersions = navigator.userAgent.toLowerCase()
.split('-ios')[0];
const version = agentVersions.toLowerCase()
.split('kolapp/')[1];
return version;
}
/**
* 判断是否是 App
*/
static isApp() {
return /kolapp/.test(navigator.userAgent.toLowerCase());
}
}
export default Agent;