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.

7
  • 16
    Best answer because I dont have to include a 33k library for a simple redirect based on browser window width Commented Jun 21, 2014 at 17:21
  • 1
    This produces the right (or expected) results consistently compared to jQuery's implementation. Commented Aug 17, 2014 at 5:04
  • 3
    ... each of these three shows some result and all results (widths) are different. For example with Google Chrome see self.innerWidth 423, document.documentElement.clientWidth 326 and document.body.clientWidth 406. In such case question: which is correct and which to use? For example i want to resize google map. 326 or 423 big difference. If width ~ 700, then see 759, 735, 742 (not so big difference)
    – Andris
    Commented Mar 13, 2015 at 4:00
  • 1
    @user2118559 var pageWidth = Math.max(self.innerWidth || 0, document.documentElement.clientWidth || 0, document.body.clientWidth || 0); and var windowWidth = self.innerWidth || -1; // because of "body" or "screen" or "document" are not the "window" if you check an overflowed content of html you can understand. # i.sstatic.net/6xPdH.png
    – Abdullah
    Commented Apr 3, 2016 at 11:32
  • 1
    @Travis is this still true in 2017? Or is window.innerWidth enough today?
    – pyronaur
    Commented Jul 25, 2017 at 16:49