Search code examples
javascriptandroidgoogle-chrometabletmobile-browser

Is there really any way to differentiate between android MOBILE chrome and android TABLET chrome through javascript?


I have this requirement where I need to identify chrome browser on Android MOBILE only but not android tablet. Have gone through several posts on stack overflow, but couldn't find any way to do this through java script.

Few related posts, which I checked:

1) Detect and differentiate Android Tablet from Android Phone via JavaScript?

2) http://www.webvanta.com/post/2012-04-08/how-to-reliably-tell-android-tablets-from-phones

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

Does this really mean that for Android, we cant differentiate between mobile and tablets? What if we need to have separate website versions for these?


Solution

  • Try using a tool like UA-Parser.js. It will correctly detect almost anything you'll want to know about the device hitting your app, including whether the device is a mobile or tablet device. I use it and can vouch that it does an excellent job. And it's free.

    The code will look something like this:

    var parser = new UAParser();
    parser.setUA(navigator.userAgent);
    var result = parser.getResult();
    
    
    
       /*
            alert(result.browser.name); 
            alert(result.browser.version);
            alert(result.device.model);
            alert(result.device.type);
            alert(result.device.vendor);
            alert(result.os.name);
            alert(result.os.version);
        */