Return to Snippet

Revision: 70835
at July 29, 2016 18:52 by envane21


Initial Code
function getMobileOperatingSystem() {
  var userAgent = navigator.userAgent || navigator.vendor || window.opera;

      // Windows Phone must come first because its UA also contains "Android"
    if (/windows phone/i.test(userAgent)) {
        return "Windows Phone";
    }

    if (/android/i.test(userAgent)) {
        return "Android";
    }

    if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
        return "iOS";
    }

    return "unknown";
}

Initial URL

                                

Initial Description
Detect the OS of mobile device

Initial Title
Detect the OS of mobile device

Initial Tags
mobile

Initial Language
JavaScript