lobo_tuerto's notes
for greatly improving DX
Blog
Notes
About

Identify a mobile browser with JavaScript

How to tell if someone is using a cell phone to browser your site.

📅Date25 April 2020
🏷️
frontendjavascript

After some research, I have found that the easiest and more reliable way to tell if the current browser is on a mobile device is with this:

Source code

function isMobile () {
  return /Mobi/.test(window.navigator.userAgent)
}

Just as the MDN says on the topic:

In summary, we recommend looking for the string “Mobi” anywhere in the User Agent to detect a mobile device.

Easy peasy, lemon squeezy! 🍋


Got comments or feedback?
Follow me on
rev-7175614