Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.