Detect touch-screen

by evpozdniakov

HTML

<div id="output">click me</div>

CSS

#output {
  position: fixed;
  top: 45%;
  width: 100%;
  text-align: center;
  font-size: 30pt;
}

JavaScript

$(document).on('touchstart.desktopDetect mousemove.desktopDetect', function(ev) {
  window.IS_TOUCHSCREEN_DEVICE = (ev.type == 'touchstart');
  $(document).off('.desktopDetect');
  $('#output').text(IS_TOUCHSCREEN_DEVICE ? 'you are TOUCH-SCREEN' : 'you are DESKTOP');
});