Search code examples
javascriptbrowser-detectionmobile-browserdevice-detection

Detecting mobile browsers on the web?


I'm curious to know how to check for iPhone, iPad and other mobile browsers.(JavaScript or CSS)

Edit:

Not user agent string, please. That can be faked.

Possible Dupes:


Solution

  • Basically you check the User Agent String

    see http://www.hand-interactive.com/resources/detect-mobile-javascript.htm

    Detect iPhone:

    navigator.userAgent.toLowerCase().search("iphone") > -1
    

    In general feature detection is better than browser detection it is better to know what the user's browser can do than what he's using. Modernizer is a good tool for that.