I am trying to apply functions for different android versions. My code is:
var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(Android)/i);
if (agentID) {
var androidversion = parseFloat(agentID.slice(agentID.indexOf("Android")+8));
if (androidversion < 4.1)
{
alert(agentID + androidversion + 'I am older than JB');
newsblocks();
} else {
alert(agentID + androidversion + 'I am JB and up');
}
} else {
alert('I am not android');
}
But for some reasons this code doesn't work and whatever version of android reads it it shows 'I am JB and up'. Can you please help me with this issue?
Thanks a lot
var agentID = deviceAgent.match(/Android\s+([\d\.]+)/)[1]
Example: http://jsfiddle.net/DZEYk/1/ http://jsfiddle.net/DZEYk/3/
From here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With