The hottest device out there right now seems to be the iPad. iPad this, iPad that, iPod your mom. I'm underwhelmed with the device but that doesn't mean I shouldn't try to account for such devices on the websites I create. In Apple's developer tip sheet they provide the iPad's user agent string:
目前最热的设备似乎是iPad。 iPad这,iPad那,iPod你的妈妈。 我对设备不满意,但这并不意味着我不应该在自己创建的网站上考虑此类设备。 在Apple的开发人员提示中,他们提供了iPad的用户代理字符串:
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10Given that string we can create a few code snippets to determine if the user is being a smug, iPad-using bastard.
给定该字符串,我们可以创建一些代码段,以确定用户是否是自欺欺人,使用iPad的混蛋。
A quick String.match regular expression test can check for the presence of "iPad" in the user agent string.
快速的String.match正则表达式测试可以检查用户代理字符串中是否存在“ iPad”。
This time we look for the position of "iPad" in the user agent string.
这次,我们在用户代理字符串中寻找“ iPad”的位置。
Using some logic from Drew Douglass' excellent mobile redirection post, we can redirect users to a mobile version of your website if you so desire.
使用Drew Douglass出色的移动重定向文章中的一些逻辑,如果您愿意,我们可以将用户重定向到您网站的移动版本。
So what would you the above tests for? You may want to redirect iPad users to a different version of your website. You may want to implement different styles to your standard website if your user is surfing on an iPad.
那么您对以上测试的目的是什么? 您可能需要将iPad用户重定向到您网站的其他版本。 如果您的用户在iPad上冲浪,则可能要对标准网站实施不同的样式。
翻译自: https://davidwalsh.name/detect-ipad
相关资源:通过JavaScript或PHP检测Android设备的代码