JavaScript detect tablet | HTML Example code

You can use the navigator API to detect whether the device browser is a tablet or not in the HTML webpage. Of course, you have to use JavaScript and Regular expression with it.

Must Read: –JavaScript detect mobile device browser

Example code JavaScript detect tablet

One line function to detect mobile devices with JavaScript.

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript">
        const userAgent = navigator.userAgent.toLowerCase();
        const isTablet = /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(userAgent);
        alert(isTablet);
    </script>
</head>
<body>

</body>
</html>

Output:

JavaScript detect tablet

Do comment if you have any questions and suggestions on this topic.

Note: The 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.