如何使用JavaScript将iPad Pro检测为iPad? [英] How to detect iPad Pro as iPad using javascript?

查看:566
本文介绍了如何使用JavaScript将iPad Pro检测为iPad?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们能够使用如下JavaScript来检测iPad设备:

We were able to detect an iPad device using javascript like this:

function isDeviceiPad(){
    return navigator.platform.match(/iPad/i);
}

这在检测iPad设备时效果很好,但是当我们从iPad Pro (10.5 inch)检查时,它并没有检测到它是iPad.

That worked perfectly in detecting iPad devices, but when we checked from an iPad Pro (10.5 inch), it does not detect that it is an iPad.

为了进一步研究,我们深入研究了navigator对象,同时检查了platformuserAgent,并获得了以下结果:

To further investigate, we drilled down into the navigator object, checked both platform and userAgent, and got these results:

navigator.platform = 'MacIntel';
navigator.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) 
 AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15)';

问题是返回了navigator.platform = 'MacIntel'(与MacBook Pro相同),而不是返回了iPad.我们需要一种方法来检测这是iPad,而不是MacBook Pro,但是导航器似乎不会像旧版iPad一样返回iPad.

The issue is that navigator.platform = 'MacIntel' (which is the same as the MacBook Pro) is returned instead of the iPad. We need a way to detect that this is an iPad and not a MacBook Pro, but it seems that the navigator does not return iPad like it does with older iPads.

您知道如何解决此问题吗?

Any idea how we can fix this issue?

推荐答案

我想iPad Pro已升级到iPadOS 13 Beta.由于Apple宣称在iPadOS上使用使用Safari进行桌面级浏览,因此移动Safari似乎也模仿了macOS行为和用户代理

I guess that iPad Pro is upgraded to iPadOS 13 Beta. Since Apple claimed Desktop-Class Browsing with Safari on iPadOS, it seems mobile Safari also mimics macOS behavior and user agent.

因此,简短的答案是不可能.

不过,您可以尝试通过解决方法来解决此问题.

However you can try workarounds from answers to this question.

这篇关于如何使用JavaScript将iPad Pro检测为iPad?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆