Last active
December 20, 2015 00:29
-
-
Save kfriend/6041800 to your computer and use it in GitHub Desktop.
JavaScript: Function to detect if user agent is a "touch" device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// Detect if user agent is on a "touch" device | |
// http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript | |
function isTouchDevice() { | |
return !!('ontouchstart' in window) // works on most browsers | |
|| !!('onmsgesturechange' in window); // works on ie10 | |
} | |
if (isTouchDevice()) { | |
document.documentElement.className += ' touch'; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment