最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Detecting whether Android device is a phone or a tablet with javascript - Stack Overflow

programmeradmin3浏览0评论

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.

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

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.

Does anyone know of a solution for this?

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.

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

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.

Does anyone know of a solution for this?

Share Improve this question asked Aug 24, 2011 at 10:05 user840533user840533 1731 gold badge1 silver badge4 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 17

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

There is no general way of doing this: read this article for more explanation http://www.webvanta.com/post/2012-04-08/how-to-reliably-tell-android-tablets-from-phones

quoting the article in case you dont have the time "Depending on the phone manufacturer and the browser in use, there are phones that don’t include “mobile” in the UA string, and tablets that do"

That is true at lease for tablets, IPads have the word mobile in user agent (for some version of chrome and safari)

发布评论

评论列表(0)

  1. 暂无评论