Created
January 11, 2023 07:37
-
-
Save tianyk/51a30afea7a00b1aea31cd2d33b7be92 to your computer and use it in GitHub Desktop.
判断系统
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 判断设备是否为 Android,包含**桌面模式** | |
* | |
* @see https://useragentstring.com/ ua 检测 | |
* | |
* @returns | |
*/ | |
function isAndroid() { | |
const ua = window.navigator.userAgent; | |
return /android/.test(ua) // android | |
|| /miuibrowser/i.test(window.navigator.userAgent) // 小米浏览器 | |
|| (/huawei/i.test(window.navigator.appPackageName)) // 华为浏览器 | |
|| ((/linux/i.test(window.navigator.platform) && window.navigator.maxTouchPoints > 0)) // android 系统平板 | |
} | |
function isMac() { | |
const ua = window.navigator.userAgent; | |
return /mac/i.test(window.navigator.platform) | |
|| /mac os/i.test(ua) | |
} | |
function isWin() { | |
const ua = window.navigator.userAgent; | |
return /win/i.test(window.navigator.platform) | |
|| /windows/.test(ua) | |
} | |
function isIOS() { | |
const ua = window.navigator.userAgent; | |
return /(ipad|ios)/i.test(ua) | |
|| (!(/chrome/.test(ua)) && /safari/i.test(ua) && window.navigator.maxTouchPoints > 0) // Safari 桌面模式 | |
} | |
function isIPad() { | |
const ua = window.navigator.userAgent; | |
return /ipad/i.test(ua) | |
|| (!(/chrome/.test(ua)) && /safari/i.test(ua) && window.navigator.maxTouchPoints > 0) // Safari 桌面模式 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment