JavaScript Snippet to detect the device type a user is browsing with. The Script is inspired by detectmobilebrowsers.com. Thanks Chad Smith for this great site.
1. Import file
Copy the
deviceTypeDetection.js
file into your website project.
2. Embed file
Place the script tag in the <head> section of your site like this:
<script src="path/to/deviceTypeDetection.js"></script>
NOTE: To use the script you have to place this script tag
before your custom javascript.
Example:
<head>
...
<script type="text/javascript" src="path/to/deviceTypeDetection.js"></script>
<script type="text/javascript">
YOUR JAVASCRIPT GOES HERE
</script>
</head>
In your custom JavaScript run
getDeviceType();
The function returns one of the following strings:
"mobile"
"tablet"
"desktop"