Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • 1
    This seems like a much better solution and actually uses CSS media queries. I wonder what the browser support is for this across mobile platforms? Commented Jan 29, 2013 at 20:53
  • 1
    Would this be the correct usage? if (window.matchMedia('(max-device-width: 960px)').matches) { var winW = (window.innerWidth > 0) ? window.innerWidth : screen.width; } else { var winW = screen.width; } Commented Feb 9, 2013 at 1:23
  • 3
    I'm not sure if this will work without the scaling set to 1:1 as a base ... var isMobile = window.matchMedia && window.matchMedia('(max-device-width: 960px)').matches || screen.width <= 960; Commented Feb 27, 2013 at 22:22
  • 3
    For Browsers not supporting matchMedia() there is a polyfill: github.com/paulirish/matchMedia.js Commented Jan 1, 2014 at 14:03
  • 4
    According to caniuse.com practically all browsers, including mobile, support window.matchMedia() Commented Jan 16, 2018 at 7:58