The easiest way to determine if there is a mobile device with javascript

What is the easiest way to determine if a device is a javascript mobile device?

I was thinking about if the height is less than or equal to the height of the browser window of the iPhone. By the way, what is an iPhone or the overall height of the viewport for mobile devices?

I'm having problems with window.height; in javascript since it was returning undefined, however?

Does anyone know how best and easy to determine if a browser is a javascript mobile device?

+6
source share
1 answer

This is what I have for my hobby project:

 var Environment = { //mobile or desktop compatible event name, to be used with '.on' function TOUCH_DOWN_EVENT_NAME: 'mousedown touchstart', TOUCH_UP_EVENT_NAME: 'mouseup touchend', TOUCH_MOVE_EVENT_NAME: 'mousemove touchmove', TOUCH_DOUBLE_TAB_EVENT_NAME: 'dblclick dbltap', isAndroid: function() { return navigator.userAgent.match(/Android/i); }, isBlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); }, isIOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, isOpera: function() { return navigator.userAgent.match(/Opera Mini/i); }, isWindows: function() { return navigator.userAgent.match(/IEMobile/i); }, isMobile: function() { return (Environment.isAndroid() || Environment.isBlackBerry() || Environment.isIOS() || Environment.isOpera() || Environment.isWindows()); } }; 

Your decision to use a measurement is not a good decision. It depends on the actual size of the device and many other variables.

+20
source

Source: https://habr.com/ru/post/945851/


All Articles