Get the device width in javascript
You can get the device screen width via the screen.width
property.
Sometimes it's also useful to use window.innerWidth
(not typically found on mobile devices) instead of screen width when dealing with desktop browsers where the window size is often less than the device screen size.
Typically, when dealing with mobile devices AND desktop browsers I use the following:
var width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
One issue with Bryan Rieger's useful answer is that on high-density displays, Apple devices report screen.width in dips, while Android devices report it in physical pixels. (See http://www.quirksmode.org/blog/archives/2012/07/more_about_devi.html .) I suggest using if (window.matchMedia('(max-device-width: 960px)').matches) {}
on browsers supporting matchMedia.