Detecting mobile browsers on the web?

前端 未结 4 1341
慢半拍i
慢半拍i 2020-12-17 04:14

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.

4条回答
  •  天涯浪人
    2020-12-17 05:04

    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.

提交回复
热议问题