How to detect only native browser for Android

it’s easy to detect an Android device, but I am having trouble finding ONLY my own Android browser. The problem is that the Dolphin browser has an almost identical user agent string, and I would like to know if they use the native browser or not.

Is it possible?

+22
javascript jquery android jquery-mobile
Feb 15 2018-12-12T00:
source share
5 answers

you just need to test several parts of the user agent string to make sure you have the default browser for Android.

var nua = navigator.userAgent; var is_android = (nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1); 

you can use the following to make sure you are not compatible with chrome in android, although on many devices chrome is used as the default browser.

 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)); 

EDIT: If you want to protect against case sensitivity, you can use the following:

 var nua = navigator.userAgent.toLowerCase(); var is_android = ((nua.indexOf('mozilla/5.0') > -1 && nua.indexOf('android ') > -1 && nua.indexOf('applewebkit') > -1) && !(nua.indexOf('chrome') > -1)); 
+20
Mar 23 '13 at 20:08
source share
β€” -

On Galaxy S3, I found that both Chrome and their own browser have "AppleWebkit", so I took this part from my conditional statement. I also added a version that only appears in my own browser. It works for me like

 var ua = navigator.userAgent; var isAndroidNative = ((ua.indexOf('Mozilla/5.0') > -1) && (ua.indexOf('Android') > -1) && !(ua.indexOf('Chrome') > -1) && (ua.indexOf('Version') > -1)) 
+3
02 Sep '15 at 14:30
source share

I think you are looking for this:

The native Android browser is not updated above version 534.30, so you can filter the version and Combination of the Android UA line (above we can assume that the Chrome browser)

Here is my sample JavaScript code:

(If you need a special style, I would add a class to the body with the following JS snippet)

 var defectAndroid = $window.navigator && $window.navigator.userAgent.indexOf('534.30') > 0 && $window.navigator.userAgent.toLowerCase().match(/android/); if (defectAndroid) { // sample code specific for your Android Stock browser } 

(Some Android devices tell "android" why we need lowercase conversation)

+2
Nov 03 '14 at 16:09
source share
 var ua = navigator.userAgent.toLowerCase(); var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile"); if(isAndroid) { // Do something! // Redirect to Android-site? window.location = 'http://android.davidwalsh.name'; } 
-7
Jul 26 '13 at 9:11
source share

You can do this with Javascript and useragent functions. What you need to do is make 2 If-request:

First you discover the type of device:

 If android, ios, mobile, ipad, iphone Take this setting 

Now you do as you need if-requests or case-request to determine the type of browser

 If chrome, firefox, safari and so on Take this setting 

This is in theory :)

-eleven
Mar 02 '14 at 12:29
source share



All Articles