Compare commits
3 Commits
66d800f195
...
7d42c5c928
Author | SHA1 | Date | |
---|---|---|---|
7d42c5c928 | |||
c7c5e7d29a | |||
8f1f348843 |
150
tools/js 判断浏览器版本号.html
Normal file
150
tools/js 判断浏览器版本号.html
Normal file
@ -0,0 +1,150 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<span id='result'></span>
|
||||
<script>
|
||||
function uaMatch(userAgent) {
|
||||
if (!userAgent) userAgent = navigator.userAgent
|
||||
|
||||
/**
|
||||
* 浏览器内核判断
|
||||
*/
|
||||
var coreRegEx =
|
||||
// Gecko
|
||||
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:104.0) Gecko/20100101 Firefox/104.0
|
||||
/(Gecko)[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
// Webkit (Chrome|Safari)
|
||||
/(Webkit)[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
// Trident (IE)
|
||||
// Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
|
||||
/(Trident)[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
[];
|
||||
var core = {
|
||||
name: coreRegEx[1] || "unknown",
|
||||
version: coreRegEx.length > 2 && coreRegEx[2] || "0",
|
||||
};
|
||||
switch (core.name.toLowerCase()) {
|
||||
case "chrome": core.name = "Chromium"; break;
|
||||
case "gecko":
|
||||
let coreRv = /rv:[ ]*([\w.]+)/i.exec(userAgent)
|
||||
if (coreRv) core.version = coreRv[1]
|
||||
break;
|
||||
}
|
||||
core.versionNumber = core.version.split(".")[0]
|
||||
|
||||
/**
|
||||
* 浏览器判断
|
||||
*/
|
||||
var browserRegEx =
|
||||
// Windows Edge
|
||||
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.62
|
||||
/(Edg)[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
// Windows Firefox
|
||||
// Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0
|
||||
// Mac Firefox
|
||||
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:104.0) Gecko/20100101 Firefox/104.0
|
||||
/(Firefox)[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
// Windows Chrome
|
||||
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
|
||||
// Mac Chrome
|
||||
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
|
||||
/(Chrome)[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
// Safari
|
||||
/(Webkit)[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
// IE
|
||||
/MS(IE) ([\w.]+)/i.exec(userAgent) ||
|
||||
[];
|
||||
var browser = {
|
||||
name: browserRegEx[1] || "unknown",
|
||||
version: browserRegEx.length > 2 && browserRegEx[2] || "0",
|
||||
};
|
||||
switch (browser.name.toLowerCase()) {
|
||||
case "webkit": browser.name = "Safari"; break;
|
||||
case "edg": browser.name = "Edge"; break;
|
||||
}
|
||||
browser.versionNumber = browser.version.split(".")[0]
|
||||
|
||||
/**
|
||||
* 系统判断
|
||||
*/
|
||||
var platformRegEx =
|
||||
/(Windows) NT ([\w.]+)/i.exec(userAgent) ||
|
||||
/(Android) ([\w.]+)/i.exec(userAgent) ||
|
||||
/(Mac) OS X ([\w_]+)/i.exec(userAgent) ||
|
||||
/(Linux)[ ]*([a-zA-Z0-9]*)/i.exec(userAgent) ||
|
||||
[];
|
||||
|
||||
var platform = {
|
||||
name: platformRegEx[1] || "unknown",
|
||||
version: platformRegEx.length > 2 && platformRegEx[2] || "0",
|
||||
}
|
||||
if (platform.name === 'unknown') {
|
||||
if (userAgent.match(/Windows/i)) platform.name = 'Windows'
|
||||
if (userAgent.match(/Macintosh/i)) platform.name = 'Mac'
|
||||
}
|
||||
platform.versionNumber = platform.version.split(/[._]/)[0]
|
||||
|
||||
/**
|
||||
* 浏览器嵌入平台判断
|
||||
*/
|
||||
var embeddedRegEx =
|
||||
// Android QQ
|
||||
// Mozilla/5.0 (Linux; Android 10; V1921A Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/98.0.4758.102 MQQBrowser/6.2 TBS/046317 Mobile Safari/537.36 V1_AND_SQ_8.9.23_3558_HDBM_T QQ/8.9.23.9800 NetType/WIFI WebP/0.3.0 AppId/537143025 Pixel/1080 StatusBarHeight/85 SimpleUISwitch/0 QQTheme/1000 StudyMode/0 CurrentMode/0 CurrentFontScale/0.9375 GlobalDensityScale/0.90000004 AllowLandscape/false InMagicWin/0
|
||||
/M(QQ)Browser[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
// Windows 微信
|
||||
// Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x63080029)
|
||||
// Android 微信
|
||||
// Mozilla/5.0 (Linux; Android 10; V1921A Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/86.0.4240.99 XWEB/4365 MMWEBSDK/20221012 Mobile Safari/537.36 MMWEBID/3234 MicroMessenger/8.0.30.2260(0x28001E55) WeChat/arm64 Weixin NetType/WIFI Language/zh_CN ABI/arm64
|
||||
/(MicroMessenger)[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
// 企业微信 *未测试
|
||||
/(wxwork)[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
// Android 支付宝
|
||||
// Mozilla/5.0 (Linux; U; Android 10; zh-CN; V1921A Build/QP1A.190711.020) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 UWS/3.22.2.55 Mobile Safari/537.36 UCBS/3.22.2.55_220929181439 ChannelId(0) NebulaSDK/1.8.100112 Nebula AlipayDefined(nt:WIFI,ws:360|0|3.0) AliApp(AP/10.3.26.8210) AlipayClient/10.3.26.8210 Language/zh-Hans useStatusBar/true isConcaveScreen/true Region/CNAriver/1.0.0
|
||||
/(Alipay)Client[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
// Android 飞书
|
||||
// Mozilla/5.0 (Linux; Android 10; V1921A Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/75.0.3770.156 Mobile Safari/537.36 Lark/5.25.4 LarkLocale/zh_CN ChannelName/Feishu TTWebView/0751130016468
|
||||
/(Lark)[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
// 钉钉 *未测试
|
||||
/(DingTalk)[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
// Android Vivo浏览器
|
||||
// Mozilla/5.0 (Linux; Android 10; V1921A; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0
|
||||
/(VivoBrowser)[ \/]([\w.]+)/i.exec(userAgent) ||
|
||||
[];
|
||||
var embedded = {
|
||||
name: embeddedRegEx[1] || "",
|
||||
version: embeddedRegEx.length > 2 && embeddedRegEx[2] || "0",
|
||||
};
|
||||
switch (embedded.name.toLowerCase()) {
|
||||
case "micromessenger": embedded.name = "Weixin"; break;
|
||||
case "wxwork": embedded.name = "WeWork"; break;
|
||||
case "":
|
||||
if (userAgent.match(/(Weixin|WeChat)/i)) embedded.name = 'Weixin';
|
||||
if (userAgent.match(/(Alipay)/i)) embedded.name = 'Alipay';
|
||||
break;
|
||||
}
|
||||
embedded.versionNumber = embedded.version.split(".")[0]
|
||||
|
||||
return {
|
||||
userAgent,
|
||||
core,
|
||||
browser,
|
||||
platform,
|
||||
embedded,
|
||||
}
|
||||
}
|
||||
document.getElementById('result').innerHTML = [
|
||||
// `<b>user-agent:</b> ${navigator.userAgent}`,
|
||||
`${JSON.stringify(uaMatch(), null, 8)}`.replace(/\n/g, '<br>').replace(/ /g, ' '),
|
||||
].join('<br>');
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
1
tools/npm ua-device.txt
Normal file
1
tools/npm ua-device.txt
Normal file
@ -0,0 +1 @@
|
||||
https://www.npmjs.com/package/ua-device
|
Loading…
Reference in New Issue
Block a user