Easiest way to determine if user is on mobile device

A user agent check is the "easiest", though you could easily employ CSS3 media queries

Here is an example that checks iphone, android and blackberry; you could easily add other mobile browsers.

var is_mobile = !!navigator.userAgent.match(/iphone|android|blackberry/ig) || false;

I find that it's best to use feature detection. Use Modernizr to detect if it's a touch device. You can do things like:

var mousedown = 'mousedown';

if (Modernizr.touch) {
    mousedown = 'touchstart';
}

$('.foo').on(mousedown, handleMouseDown);

And then use CSS Media Queries for handling screen width (and it's also easy to detect screen width with javascript). That way you can correctly handle touch devices with large screens, or non-touch devices with small screens.


Check this http://detectmobilebrowsers.com/

Work for Javascript, jQuery etc.