There isn't a direct way to access media queries through JS as window
properties, but there are plugins available that can handle this functionality.
An alternative approach is to utilize standard CSS queries to style a specific element in a unique way that can be easily detected using JavaScript.
CSS:
@media screen and (-webkit-min-device-pixel-ratio: 1.3), (min-resolution: 124.8dpi), (max-device-width: 550px) {
head { font-family: 'someValue'; }
}
JS (w/ jQuery):
$(function() {
var foo = $('head').css('fontFamily').split("\"").join("").split("'").join(""); // use split/join for cross-browser compatibility
if(foo === 'someValue') {
doStuff();
} else if(foo === 'someOtherValue') {
doOtherStuff();
}
}
It may seem like a workaround, but it gets the job done. I've adapted similar code for responsive design purposes.