在iOS 13中,苹果改变了iPad使用的用户代理。
而不是(例如)
Mozilla/5.0(iPad;U;CPU iPhone OS 3_2,类似Mac;en-us) AppleWebKit/531.21.10 (iPhone,类似Gecko)版本/4.0.4Mobile/7B314 Safari/531.21.10
它变成(例如)
Mozilla/5.0 (Macintosh;Intel Mac 10_15) AppleWebKit/605.1.15 (KHTML,类似Gecko)版本/13.0Safari/605.1.15
我的问题是,我们现在如何区分iPad和mac?
发布于 2019-12-05 03:13:06
我用来检测IpadOS的条件:
ua.toLowerCase().indexOf('macintosh') > -1 && navigator.maxTouchPoints && navigator.maxTouchPoints > 2发布于 2020-07-19 13:24:58
不幸的是,仅仅通过用户代理字符串这样做似乎不再可能了。如果您是服务器端,需要以不同的方式共享下载,就像您在评论中提到的那样,这是个小问题。
但是,下面应该可靠地检测到客户端的iPads:
const iPad = !!(navigator.userAgent.match(/(iPad)/)
|| (navigator.platform === "MacIntel" && typeof navigator.standalone !== "undefined"))它避免依赖带有触摸屏监视器的Mac上发生的触摸事件,而是使用navigator.standalone,这是iOS 唯一的属性。
发布于 2020-04-01 14:23:28
结合quangh的answer和Michael的answer来检测包括iPads在内的移动设备。
detectMobile() {
let isMobile = RegExp(/Android|webOS|iPhone|iPod|iPad/i)
.test(navigator.userAgent);
if (!isMobile) {
const isMac = RegExp(/Macintosh/i).test(navigator.userAgent);
if (isMac && navigator.maxTouchPoints && navigator.maxTouchPoints > 2) {
isMobile = true;
}
}
return isMobile;
}https://stackoverflow.com/questions/56934826
复制相似问题