Javascript – detect what type of mobile

  |   By  |  0 Comments

For one of my apps, I have a landing page website –, that detects if a mobile phone or tablet has accessed it and redirects to the correct app store. I use a javascript function to detect iOS, Android, Windows and Amazon – although Windows doesn’t go anywhere – so few people use it on mobile devices, I haven’t bothered developing for it.

function getMobileOperatingSystem() {
  var userAgent = navigator.userAgent || navigator.vendor || window.opera;
  var os="Unknown";
      // Windows Phone must come first because its UA also contains "Android"
    if (/windows phone/.test(navigator.userAgent)) {
        os= "Windows Phone";
  	/* Kindle before Android as the UA contains Android too */
        os= "Amazon";
    if (/android/.test(navigator.userAgent)) {
        os= "Android";
    // iOS detection from:
    if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
       os = "iOS";
    return os;


Andy Moyle is a church leader and web developer. His biggest project is the Church Admin WordPress plugin and app. He also runs, mainly so he can eat pizza.