检测 iPad Safari 或 Zoom
如果我使用以下内容来检测 iPad Safari 用户,如果将来我尝试检测 Motorola Xoom 或其他可能具有相似宽度的平板电脑用户,它会起作用吗?
<link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px)" href="ipad.css">
我的意思是我将如何准确地识别其他平板电脑并使用 xoom.css 或 othertablet.css
我知道用户代理方法,但希望避免这种情况。请告诉我是否可以仅使用媒体查询来实现?
If I use the following to detect iPad Safari user, will it work if in future, I try to detect a Motorola Xoom or other tablet user, which might have similar widths.
<link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px)" href="ipad.css">
I mean how exactly will I identify the other tablet and use xoom.css or othertablet.css
I know the user-agent approach, but would want to avoid that. Please let me know if it is possible to implement using media queries only?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,您无法根据媒体查询判断正在使用什么特定设备(并且您不需要这样做,因为它们都收敛于相同的标准)
No, you can't tell what specific device is being used based on media queries (and you shouldn't need to as they are all converging on the same standards)
我们开始使用 Formfactor 检测库进行开发,例如 FormfactorJS - 请注意,这是我创建的。
使用相同语义 HTML 的理论,您可以将 CSS 和 Javascript 专门用于给定类别的设备(智能手机、平板电脑、台式机等),同时还可以使用媒体查询了解对单个设备配置文件的响应式设计。
至少好的一点是,您可以指定自己的检测算法,这样您就可以检测同一类设备的不同类型(即 iPad 或 Xoom)。在本例中,我们选择通过 userAgent 检查来执行此操作。为什么?因为根据外形尺寸或设备类型,您可能希望提供优化的体验。
We are starting to develop using Formfactor detection libraries such as FormfactorJS - note, I created this.
The theory being using the same semantic HTML, you can specialize your CSS and Javascript using for a given class of device (smartphone, tablet, desktop etc) whilst also being cognizant of responsive design to individual device profile using Media Queries.
The good thing at least, is that you can specify your own detection algorithms, so you can detect different types of the same class of device (i.e, iPad or Xoom). We chose to do this through userAgent checking in this case. Why? because depending on the formfactor or device type you might want to offer optimised experiences.