JavaScript detect mobile or tablet | HTML Example code

The Simplest way is using vanilla JavaScript navigator API to detect mobile or tablet in HTML webpage. You have to regex (regular expression) in the query.

You can also use a 3rd party library such as wurfl.io:- https://web.wurfl.io/#wurfl-js

Example of JavaScript detect mobile or tablet

Using a console log to print message, IT will print message for tablet and mobile.

You can use it detect if the device is ONLY tablet or mobile.

Output:

JavaScript detect mobile or tablet

All major browser provides a very useful API to know the user’s device and the browser details.

Do comment if you have better example or doubts or suggestions this topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.