Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting whether Android device is a phone or a tablet with javascript

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?

like image 316
user840533 Avatar asked Aug 24 '11 10:08

user840533


People also ask

How can I tell if a device is mobile JavaScript?

To detect if the user is using a mobile device in JavaScript, we can use the userAgent property. This property is part of the navigator object and sent by the browser in HTTP headers. It contains information about the name, version, and platform of the browser.

How do you identify a mobile phone?

The easiest way to check your phone's model name and number is to use the phone itself. Go to the Settings or Options menu, scroll to the bottom of the list, and check 'About phone', 'About device' or similar. The device name and model number should be listed.


1 Answers

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

like image 109
JSantos Avatar answered Sep 17 '22 08:09

JSantos