Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2013 06:07
Show Gist options
  • Select an option

  • Save anonymous/5352184 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/5352184 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Apr 10, 2013.
    60 changes: 60 additions & 0 deletions detectMobile.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    <!-- @Reference : http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript/ -->
    <html>
    <head>
    <!-- For Syntax Highlighting -->
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <link rel="stylesheet" type="text/css" href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css"></link>
    <script src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js"></script>
    <script>
    function styleCode() {
    if (typeof disableStyleCode != 'undefined') { return; }

    var a = false;

    $('code').each(function() {
    if (!$(this).hasClass('prettyprint')) {
    $(this).addClass('prettyprint');
    a = true;
    }
    });

    if (a) { prettyPrint(); }
    }

    $(function() {styleCode();});
    </script>
    <script>
    function checkDevice(){
    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());
    }
    };

    if(isMobile.iOS()) alert('iOS');
    else if( isMobile.Android() ) alert('Android');
    else if( isMobile.any() ) alert('Mobile');
    else alert('You are on Mac or PC');
    }
    </script>
    </head>
    <body onload="checkDevice()">
    </body>

    </html>