Testing for mobile in JavascriptPosted on: October 07, 2011

Just a quick one on how to get a variable that you can use in your conditionals for when certain functionality is not ideal for on mobile.

var MOBILE =
  (navigator.userAgent.match(/Android/i) ||
    navigator.userAgent.match(/webOS/i) ||
    navigator.userAgent.match(/iPhone/i) ||
    navigator.userAgent.match(/iPod/i) ||
    navigator.userAgent.match(/iPad/i)) != null;

That'll do for now I think. Any comments/suggestions are welcome.