How do I check if the useragent is an ipad or iphone?

前端 未结 9 2524
礼貌的吻别
礼貌的吻别 2020-12-09 14:42

I\'m using a C# asp.net website.

How can I check if the user using ipad or iphone? How can I check the platform?

For example, if the user enter the websi

9条回答
  •  無奈伤痛
    2020-12-09 15:24

    For iPad user agent is something like:

    Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10

    and for iPhone its somthing like:

    Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3

    Any many more depending on the version and wheather its iPhone 3 or 4

    so better just do a substring search for iPhone and iPad as suggested by another answer

提交回复
热议问题