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));
bizzehdee Mar 23 '13 at 20:08 2013-03-23 ββ20:08
source share