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);
},
webOS: function () {
return navigator.userAgent.match(/webOS/i);
},
any: function () {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
var tell_if_mobile;
var mobile_tablet;
if (isMobile.any()) {
tell_if_mobile = true;
} else {
tell_if_mobile = false;
var windowWidth = window.screen.width < window.outerWidth ?
window.screen.width : window.outerWidth;
tell_if_mobile = windowWidth < 800;
mobile_tablet = windowWidth >= 500 ? "Tablet/Phablet Device" : "Desktop View (Mobile)";
}
var mobile_type;
mobile_type = isMobile.Android() ? "Android Device" :
isMobile.BlackBerry() ? "Blackberry Device" :
isMobile.iOS() ? "iOS Device" :
isMobile.Opera() ? "Opera Mobile/Mini" :
isMobile.Windows() ? "IEMobile" :
isMobile.webOS() ? "webOS device" :
tell_if_mobile == true ? mobile_tablet :
"Not a mobile device";
alert(mobile_type);
source
share