2020 / 04 / 25
2023 / 04 / 04
Identify a mobile browser with JavaScript

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


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! :lemon: