Skip to content

Instantly share code, notes, and snippets.

@dperini
Created April 28, 2010 00:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dperini/381530 to your computer and use it in GitHub Desktop.
Save dperini/381530 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>TouchEvent detection for iPhone/iPod/iPad</title>
<script type="text/javascript">
var isTouch = (function() {
var event, feature = false,
support = function() { feature = true; },
element = document.createElement('div');
try {
event = document.createEvent('TouchEvent'),
event.initTouchEvent('touchstart', true, true, document.defaultView);
element.addEventListener('touchstart', support, false);
element.dispatchEvent(event);
} catch(e) {
feature = false;
}
return feature;
})();
alert(isTouch);
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment