Skip to content

Instantly share code, notes, and snippets.

@davidaurelio
Created September 6, 2011 17:10
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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