Skip to content

Identify a mobile browser with JavaScript

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

1 min read

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

JavaScript
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! 🍋

More notes connected by topic, not algorithmic noise.