Skip to content

Instantly share code, notes, and snippets.

@kfriend
Last active December 20, 2015 00:29
Show Gist options
  • Save kfriend/6041800 to your computer and use it in GitHub Desktop.
Save kfriend/6041800 to your computer and use it in GitHub Desktop.
JavaScript: Function to detect if user agent is a "touch" device
<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