Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<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