uni-app如何区分安卓手机和安卓pad
7***@qq.com
- 发布:2021-05-20 11:00
- 更新:2022-12-27 11:05
- 阅读:2564
试一下这个看看行不行:
console.log(navigator.userAgent);
var os = function() {
var ua = navigator.userAgent,
isWindowsPhone = /(?:Windows Phone)/.test(ua),
isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone,
isAndroid = /(?:Android)/.test(ua),
isFireFox = /(?:Firefox)/.test(ua),
isChrome = /(?:Chrome|CriOS)/.test(ua),
isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox && /(?:Tablet)/.test(ua)),
isPhone = /(?:iPhone)/.test(ua) && !isTablet,
isPc = !isPhone && !isAndroid && !isSymbian;
return {
isTablet: isTablet,
isPhone: isPhone,
isAndroid: isAndroid,
isPc: isPc
};
}();
if(os.isAndroid || os.isPhone) {
alert("手机")
} else if(os.isTablet) {
alert("平板")
} else if(os.isPc) {
alert("电脑")
}
祈愿稻荷神
可以稍微优化下:
APP端换成=> var ua = plus.navigator.getUserAgent()
非APP的=> var ua = navigator.userAgent,
2022-11-11 15:31