Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript detect android native browser

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 ?

like image 253
Razvan Avatar asked Feb 05 '13 07:02

Razvan


People also ask

Can I detect the browser with JavaScript?

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.

What is the best way to detect a mobile device JavaScript?

matchMedia() The Window. matchMedia() is one of the best properties for detecting mobile users with JavaScript.

How can I tell if my browser is mobile or desktop JavaScript?

You can use JavaScript window. matchMedia() method to detect a mobile device based on the CSS media query. You may also use navigator.

What is the best way to detect a mobile device?

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.


2 Answers

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));
like image 188
PRASS Avatar answered Oct 19 '22 10:10

PRASS


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:

enter image description here

and in the native browser:

enter image description here

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... :)

like image 8
Kailas Avatar answered Oct 19 '22 09:10

Kailas