3

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

qqruza
  • 1,275
  • 4
  • 19
  • 38
  • 1
    Can you not use feature detection? Why JellyBean in particular? – MDEV Sep 26 '13 at 16:49
  • possible duplicate of [Detect Android phone via Javascript / jQuery](http://stackoverflow.com/questions/6031412/detect-android-phone-via-javascript-jquery) – Emilio Gort Sep 26 '13 at 16:50
  • I have got problem with one of the plugins (swiper jumps on the screen) on the 4.0.4. It works fine on 4.1 though – qqruza Sep 26 '13 at 16:50

1 Answers1

4

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

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

From here

Community
  • 1
  • 1
Cristi Pufu
  • 8,637
  • 3
  • 31
  • 41
  • Hi Cristi, almost there but my line: if (version < 4.1) doesn't work at all I am afraid. Can you help me with full solution in you fiddle please? – qqruza Sep 26 '13 at 16:59