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 ?
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 ?
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... :)
Try something like this:
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
// Do something
}
or
check this url: http://davidwalsh.name/detect-android