HTML webpage can detect detect mobile device using JavaScript. Use the JavaScript with regular expression test to detect if browser is a mobile device or not.
Example of JavaScript detect mobile device browser
Here’s a code that uses an insanely long and comprehensive regex which returns a true
or false
value depending on whether or not the user is browsing with a mobile.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<!DOCTYPE html> <html> <head> <script type="text/javascript"> const userAgent = navigator.userAgent.toLowerCase(); var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) if(isMobile){ alert("mobile device"); }else{ alert("not mobile device"); } </script> </head> <body> </body> </html> |
Output:

Do comment if you have another better way or doubts or suggestion on this topic.
Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version