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.

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다

Back To Top