使用javascript检测Android设备是手机还是平板电脑 [英] Detecting whether Android device is a phone or a tablet with javascript

查看:22
本文介绍了使用javascript检测Android设备是手机还是平板电脑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚建立了一个移动网站,并希望在用户通过手机浏览时重定向来自我们主网站的流量.

I have just built a mobile site and want to redirect the traffic from our main site if the user is browsing through a mobile phone.

目前我正在使用 javascript 来获取浏览器用户代理并使用它来识别设备是否是手机.

Currently I am using javascript to pick up the browser useragent and using that to identify if the device is a mobile phone.

我遇到的问题是 Android 设备,因为我找不到 Android 用户代理的区别功能来决定设备是手机还是平板电脑,如果用户使用平板电脑,我仍然想向他们展示完整的网站.

The issue I have is with Android devices as I cannot find a distinguishing feature for Android useragents to decide whether the device is a phone or a tablet, If the user is on a tablet I still want to show them the full site.

有人知道解决方案吗?

推荐答案

您可能应该通过阅读用户代理来使用谷歌提出的这个建议.如果 UA 有mobile"这个词,那就是手机,如果没有,那就是平板电脑

You should probably use this sugestion made by google by reading the user agent. If the UA has the word mobile it's a phone, if it doesn't it's a tablet

http://googlewebmastercentral.blogspot.com/2011/03/mo-better-to-also-detect-mobile-user.html

这篇关于使用javascript检测Android设备是手机还是平板电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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