Skip to content

Instantly share code, notes, and snippets.

@yuanotes
Last active December 22, 2017 08:03
Show Gist options
  • Save yuanotes/6ab934604a3a664a50be4c2d9ec3942a to your computer and use it in GitHub Desktop.
Save yuanotes/6ab934604a3a664a50be4c2d9ec3942a to your computer and use it in GitHub Desktop.
Detect browser with UA in China
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