Languages
[Edit]
EN

JavaScript - detect mobile device

3 points
Created by:
Ela-Davey
663

In this article, we would like to show you how to detect mobile devices using JavaScript​​​​​.

Practical examples

Edit

In the below examples, we use two regular expressions to test the user agent string. We check if the device is mobile or tablet and assume that any other device is a desktop type.

Example 1:

Edit

Example 2:

Edit

 

Example test

Edit

 

See also

Edit
  1. JavaScript - check operating system (in web browser)

  2. Example User-Agent values

References

Edit
  1. RegExp.prototype.test() - JavaScript | MDN
  2. Navigator.userAgent - Web APIs | MDN

Alternative titles

  1. JavaScript - detect if used device is mobile (from User-Agent)
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join