I want to detect with javascript the native android browser (the one that comes installed on every android phone).
What should I look for in useragent ?
Browser Detection with JavaScript. If you really must do it, detecting what browser someone is using is easy with JavaScript. JavaScript has a standard object called navigator that contains data about the browser being used.
matchMedia() The Window. matchMedia() is one of the best properties for detecting mobile users with JavaScript.
You can use JavaScript window. matchMedia() method to detect a mobile device based on the CSS media query. You may also use navigator.
In summary, we recommend looking for the string “Mobi” anywhere in the User Agent to detect a mobile device. Like this: if (/Mobi/. test(navigator.
This should work.
var nua = navigator.userAgent;
var is_android = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));
Native browser, we could not detect at the first go itself, using the above mentioned code:
var nua = navigator.userAgent;
var is_android = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));
as for most devices we got the following as the user agent for chrome browser:
and in the native browser:
And carried out this observation for Samsung Galaxy S3, htc desire, Asus Zenfone5.
And found out that the "Chrome/30.0.0.0" or the "chrome/" along withthe version is present for most devces including Zenfone 5, Samsung Galaxy s3. But the "version/" no. present in the user agent object is more than enough to differentiate the native and the Chrome.
We used the following code:
var ua = navigator.userAgent;
var is_native_android = ((ua.indexOf('Mozilla/5.0') > -1 && ua.indexOf('Android ') > -1 && ua.indexOf('AppleWebKit') > -1) && (ua.indexOf('Version') > -1));
Hope, it's useful for you too... :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With