Skip to content

Instantly share code, notes, and snippets.

@magician11
Created October 31, 2016 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magician11/b0542cd51d9ee31034afa19e3bb719e1 to your computer and use it in GitHub Desktop.
Save magician11/b0542cd51d9ee31034afa19e3bb719e1 to your computer and use it in GitHub Desktop.
Testing for touch screen devices
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Touchscreen Test</title>
<style>
body {
text-align: center;
}
</style>
</head>
<body>
<h1>Touch Screen Test</h1>
<p>Result: <span class="result"></span></p>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script>
// Touch Device Detection
var isTouchDevice = 'ontouchstart' in document.documentElement;
var response = isTouchDevice ? 'This is a touchscreen' : 'This is not a touchscreen';
$('.result').text(response);
</script>
</body>
</html>
@magician11
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment