- From: Tab Atkins Jr. <jackalmage@gmail.com>
- Date: Mon, 2 Jul 2012 10:59:53 -0700
- To: Boris Smus <smus@google.com>
- Cc: www-style@w3.org
On Sat, Jun 30, 2012 at 9:35 PM, Boris Smus <smus@google.com> wrote: > Hi Folks, > > Section 3.1 of the Media Query specification > (http://www.w3.org/TR/css3-mediaqueries/) says "Unknown media types evaluate > to false". While this might be acceptable for declarative CSS (sorta), it > poses problems in JavaScript using the window.matchMedia function > (http://dev.w3.org/csswg/cssom-view/#mediaquerylist). > > # Problem > > Here's the problem: there is no way to tell if a media query is implemented > in a given user agent, because unknown media features still evaluate to > false. Really, there are three possibilities: 1) MQ matches 2) MQ doesn't > match 3) MQ Is invalid. For example, in Chrome, the following returns false: > > matchMedia('(min--moz-device-pixel-ratio: 2)').matches > > which can imply either than the query didn't match, or was invalid. This > particular case is obviously invalid since moz-prefixing, but the general > case is very confusing because there's no distinction between "no match" and > "invalid". In a conforming browser (FF and Opera do it right I think, WebKit doesn't, don't know about IE), you can test this by putting the MQ in a stylesheet and then reading it back out. If it comes out with the query transformed into "not all", it's an unsupported query. That said, this is slightly clumsy. I'm not against your proposal to add an explicit validity boolean to the returned value of matchMedia. ~TJ
Received on Monday, 2 July 2012 18:00:41 UTC