Search code examples
javascriptcssbrowser-feature-detection

Newest method to detect small screen


While waiting for responsive design to find the way into a legacy web site, I would like to redirect a browser to a mobile version if the screen is smaller than 480px

Hunting around I came up with

var isSmall = window.matchMedia ? 
              window.matchMedia("screen and (max-width: 480px)") : 
              screen.width<=480;

Question

Is this acceptable in 2014 or is there a better/safer/newer method to do what I want without using useragent sniffing?

References


Solution

  • You could use a polyfill such as https://github.com/paulirish/matchMedia.js/