Last active
December 22, 2017 08:03
-
-
Save yuanotes/6ab934604a3a664a50be4c2d9ec3942a to your computer and use it in GitHub Desktop.
Detect browser with UA in China
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
const ua = navigator.userAgent.toLowerCase(); | |
export function isWechat() { | |
return /micromessenger/i.test(ua); | |
} | |
export function isAndroid() { | |
return /android/i.test(ua); | |
} | |
export function isIOS() { | |
return /(ipad|iphone)/i.test(ua); | |
} | |
export function getIOSVersion() { | |
const re = /(ipad|iphone); cpu (iphone )?os (\d+)/i; | |
const match = re.exec(ua); | |
if (match) { | |
return match[3]; | |
} | |
return null; | |
} | |
export function isMobile() { | |
return /(ipad|iphone|ipod|android|webos)/i.test(ua); | |
} | |
export function isDesktop() { | |
return !isMobile(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment