Checking if viewport has correct size

By | 2012/11/17
var wmq = window.matchMedia("(min-width: 400px)");
if (wmq.matches) {
  /* the view port is at least 400 pixels wide */
} else {
  /* the view port is less than 400 pixels wide */
}

Event listener:

wmq.addListener(function(wmq) {
    console.log(wmq.media + " " 
        + (wmq.matches ? 'matches' : "doesn't match"));
});

Suppored in all browsers. (IE10+)