Skip to content

Instantly share code, notes, and snippets.

@davidaurelio
Created September 6, 2011 17:10
Show Gist options
  • Save davidaurelio/1198220 to your computer and use it in GitHub Desktop.
Save davidaurelio/1198220 to your computer and use it in GitHub Desktop.
Checking for touch support
<!doctype html>
<title>has touch?</title>
<h1>Has this device touch? </h1>
<script>
var isTouch = (function(){
try{
var event = document.createEvent("TouchEvent"); // Should throw an error if not supported
return !!event.initTouchEvent; // Check for existance of initialization method
}catch(error){
return false;
}
}());
document.getElementsByTagName("h1")[0].innerHTML += isTouch ? "yes" : "no";
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment