Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if android version < 4.1 with jquery

Tags:

jquery

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

like image 455
qqruza Avatar asked Aug 14 '26 00:08

qqruza


1 Answers

var agentID = deviceAgent.match(/Android\s+([\d\.]+)/)[1]

Example: http://jsfiddle.net/DZEYk/1/ http://jsfiddle.net/DZEYk/3/

From here

like image 191
Cristi Pufu Avatar answered Aug 16 '26 09:08

Cristi Pufu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!