navigator.useragent mobiles including ipad

By Sam Deering

Code snippets to detect mobiles including ipad using navigator.useragent.

function detectmob() {
     return !!navigator.userAgent.match(/iPad|iPhone|Android|BlackBerry|Windows Phone|webOS/i));

Kindle Fires and PlayBooks are not detected by design. To add support for tablets, add |playbook|silk

Other ways

var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());

How to use

if( isMobile.any() ) alert('Mobile');

To check to see if the user is on a specific mobile device:

if( isMobile.iOS() ) alert('iOS');


No Reader comments



Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.