Reputation:
Is it possible to detect media queries with javascript with out using Modernizr and similar libraries? I only need to see if media queries are there and maybe which widths.
EDIT: My problem. I am making a chrome extension that need to be able to see if the current site is using media queries without having to re-size the viewport.
In a nut shell I just want to check if a site is using media queries with javascript alone. is that possible?
Upvotes: 4
Views: 479
Reputation: 268344
You could try checking for CSSMediaRule
objects within the document.styleSheets
collection. For example, the Modernizr website uses media queries, and we know this, so we can check by examining their stylesheet objects:
document.styleSheets[0].cssRules; // CSSRuleList
Within this list we simply look for any CSSMediaRule
; we happen to find 3 on their site.
Upvotes: 1