-5

hi all i am looking for simple javascript just to determination if the user use IOS or ANDROID so if user use IOS i will show the div say: download app from Apple store if Android i will say download app from play store. how i can know the type of the device ? and show the div depend on that? also i need to test it where i can test this script if work well as a IOS and Android environment or not ? is it easy to do that ? i am using HTMl and Javascript for this the idea here i will show div for first time only when the user visit the site to download the app i did it but am looking to determination the device type if its IOS or Android

user3469218
  • 13
  • 1
  • 7
  • 2
    Did you even try to find an answer yourself? – René Roth Mar 31 '14 at 07:35
  • var isMobile = { Android: function() { return navigator.userAgent.match(/Android/i) ? true : false; }, BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i) ? true : false; }, iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false; }, Windows: function() { return navigator.userAgent.match(/IEMobile/i) ? true : false; }, any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows()); } }; – Pratik Joshi Mar 31 '14 at 07:38

1 Answers1

0

try this:

 var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }

};



if (isMobile.Android()) {
     //android code.
}
else if(isMobile.iOS())
{
     //ios code.
}
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125