Created
September 6, 2011 17:10
-
-
Save davidaurelio/1198220 to your computer and use it in GitHub Desktop.
Checking for touch support
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
<!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