I\'m building a web app and wanting to disable transitions effects on Android devices under version 3.0.
Is there anyway to pick up the Android version number by Ja
It's better to check first if device is android or not as Windows mobile can have Android in its user agent.
Example: Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; ; ) AppleWebKit/ (KHTML, like Gecko) Chrome/ Mobile Safari/ Edge/.
Here is way to check it Detecting iOS / Android Operating system
You can look at the user agent string - window.navigator.userAgent
described here: https://developer.mozilla.org/en/DOM/window.navigator.userAgent
If what you're really trying to detect is whether you have a version of the browser that supports a particular feature, then it's nearly always better to use feature detection instead of browser version detection. modernizr is a huge base of code for feature detection that you can either use as is or borrow one particular piece from or just learn how the general technique works.
When I Google, I see user agent strings like this for Android:
Mozilla/5.0 (Linux; U; Android 2.2.1; fr-ch; A43 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
A regex of /Android\s+([\d\.]+)/
on window.navigator.userAgent
will pick up the Android version number.
This code checks the full version of Android from the useragent.
var test = LowerThanAndroidVersion('4.4');
if (test) {
alert('lower than android 4.4')
} else if (test == undefined) {
alert('no android')
} else {
alert('android 4.4 or higher');
}
function LowerThanAndroidVersion(testversion) {
//var useragent = 'Mozilla/5.0 (Linux; U; Android 4.3.1; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';
var useragent = navigator.userAgent;
var androidpoint = useragent.indexOf('Android');
if (androidpoint >= 0) {
var rest = useragent.substring(androidpoint + 8, useragent.length);
var version = rest.substring(0, rest.indexOf(';'));
return (version < testversion) ? true : false;
}
}