in HTML, JavaScript

Javascript – how to know the device (android, iOS, etc) on html

i got some article by stack overflow.

you can you use the following thing.

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

how to use this?

just call the function.

// if you want to check it's android or not just do it.
if (isMobile.Android()) {
    // Android
} else {
    // something else
}

thank you for reading.

Write a Comment

Comment