Detect Browser, Platform, and Touch Capability Using Javascript

Here’s a method of detecting which browser you’re using and whether you’re on a mobile or desktop platform:

<script type="text/javascript">
  <!--
  var userAgent = navigator.userAgent || window.navigator.userAgent;
  var nav = navigator || window.navigator;
  var isDesktop = nav['platform'].match(/(Mac|Win|Linux)/) && !userAgent.match(/Android/);
  if (isDesktop) {
    alert("You're on a Desktop!");
  };
  -->
</script>

Need to detect if the device you’re on is touch capable? Try this:

<script type="text/javascript">
  <!--
  if('ontouchstart' in document.documentElement) {
    // Add touch events.
  }
  else {
    // Add mouse events.
  };
  -->
</script>