Skip to content

JavaScript detect tablet | HTML Example code

  • by

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

Your email address will not be published. Required fields are marked *