问题
Does Apple have any recommendation for using any technique for browser sniffing (e.g. to distinguish between desktop IE/ FF / Mobile Safari (i.e. iPad)) / Other tablets
I know Apple wants us to avoid using User-agent for the same.
Is the media technique foolproof way to differentiate between iPad and say Xoom?
<link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px)" href="ipad.css">
回答1:
Rather than trying to detect device/user-agent, you want to focus on checking the capabilities of the browser. This includes screen resolution, JS support, CSS support, and more.
Media queries is only one of many techniques you can employ to make your website work well across many devices. To get you started, here are a few helpful resources:
- Modernizr - A JS library that detects browser capabilities and adds handy CSS classes and JS methods to check this
- "Mobifying" your HTML5 site - HTML5 Rocks - An article on various techniques
- Yiibu - a proof of concept, progressively enhanced site
- Using media queries in the real world - Broken Links - An article promoting starting with a barebones stylesheet and then using media queries to add extra styles on top
回答2:
See Optimizing Web Content on the Apple developer network. This article includes using conditional css to identify browser capabilities, and the differences in various user-agent strings sent by Safari browsers.
来源:https://stackoverflow.com/questions/5733268/apples-recommendation-on-browser-sniffing