检测客户端是平板电脑还是手机的最佳方法是什么? [英] What's the best way to detect whether the client is a tablet or a phone?

查看:178
本文介绍了检测客户端是平板电脑还是手机的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一款专为智能手机和平板电脑设计的客户端应用程序。因此它将获得两种不同的布局模式。

I am currently developing a client side application which will be designed for both, smartphones and tablets. Therefore it will get two different layout modes.

虽然用户可以在两种模式之间切换,但我必须在第一次使用应用程序时预先设置模式。

While the user will be able to switch between the two modes, I will have to pre-set the mode by the first use of the app.

所以我正在寻找一种可靠的方法来自动检测用户是否带有打击垫或智能手机(桌面浏览器不相关)。

So I am looking for a reliable way to automatically detect whether the user comes with a pad or a smartphone (desktop browsers aren't relevant).

我可以查看浏览器的分辨率,但我不确定这是否是通往罗马的正确方法,因为960x640px的iPhone 4的分辨率几乎与1024x768的iPad屏幕分辨率一样高,并且保持不变记住Android设备。

I could check the browsers resolution, but I am uncertain if that's the right way to Rome, as the resolution of the iPhone 4 with 960x640px is nearly as high as the screen resolution of the iPad with 1024x768, and to keep in mind the android devices.

有什么建议吗?

推荐答案

你可以使用 http://detectmobilebrowser.com/ 脚本检测是否是手机。如果没有,您可以认为它是平板电脑(因为,正如您所提到的,桌面浏览器与此应用程序无关)。

You could detect whether it is a phone using a http://detectmobilebrowser.com/ script. If not, you can assume it is a tablet (since, as you mentioned, desktop browsers are irrelevant for this app).

这篇关于检测客户端是平板电脑还是手机的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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