Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Fixed with now 3 logics to identify a mobile ?
Source Link
molokoloco
  • 4.6k
  • 2
  • 36
  • 28

Like yoav barneaThe best must be :

var isMobile = (/Mobile/i.test(navigator.userAgent)); 

But like like Yoav Barnea says, but updated...

// Seem legit var mobileisMobile = ('DeviceOrientationEvent' in window || 'orientation' in window); // MyBut Chromewith desktopmy onChrome windowon havewindows, DeviceOrientationEvent == fct() if (/Windows NT|Macintosh|LinuxNT|Macintosh|Mac OS X|Linux/i.test(navigator.userAgent)) mobileisMobile = false; // My android have "linux" too if (/Mobile/i.test(navigator.userAgent)) isMobile = true; 

After this 3 tests, i hope var isMobile is... ok

Like yoav barnea says, but updated...

var mobile = ('DeviceOrientationEvent' in window || 'orientation' in window); // My Chrome desktop on window have DeviceOrientationEvent == fct() if (/Windows NT|Macintosh|Linux/i.test(navigator.userAgent)) mobile = false; 

The best must be :

var isMobile = (/Mobile/i.test(navigator.userAgent)); 

But like like Yoav Barnea says...

// Seem legit var isMobile = ('DeviceOrientationEvent' in window || 'orientation' in window); // But with my Chrome on windows, DeviceOrientationEvent == fct() if (/Windows NT|Macintosh|Mac OS X|Linux/i.test(navigator.userAgent)) isMobile = false; // My android have "linux" too if (/Mobile/i.test(navigator.userAgent)) isMobile = true; 

After this 3 tests, i hope var isMobile is... ok

Source Link
molokoloco
  • 4.6k
  • 2
  • 36
  • 28

Like yoav barnea says, but updated...

var mobile = ('DeviceOrientationEvent' in window || 'orientation' in window); // My Chrome desktop on window have DeviceOrientationEvent == fct() if (/Windows NT|Macintosh|Linux/i.test(navigator.userAgent)) mobile = false;