Skip to main content
14 events
when toggle format what by license comment
Jan 16, 2020 at 2:14 comment added hyperknot Warning! If you are trying to use it to detect browser's portrait/landscape mode or the screen's aspect ratio, the heigh values will return the very long, multi-page height. For example on this very page: 7305. The only value you should use is window.outerHeight/Width!
Feb 4, 2019 at 9:16 vote accept Amr Elgarhy
Jul 31, 2017 at 20:43 comment added Travis @Norris I've updated my answer. I looked at the jQuery source to see how they do it now (in 2017). While window.innerWidth will probably work in most cases, I trust the jQuery team and their ability to maintain cross-browser consistency. For that reason, I use their code, only modified to run without the full jQuery library.
Jul 31, 2017 at 20:40 history edited Travis CC BY-SA 3.0
Update for 2017. Fix minor formatting.
Jul 25, 2017 at 16:49 comment added pyronaur @Travis is this still true in 2017? Or is window.innerWidth enough today?
Aug 18, 2016 at 18:17 history edited Travis CC BY-SA 3.0
Fixed typo in code
Apr 3, 2016 at 11:32 comment added Abdullah @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
S Feb 9, 2016 at 12:16 history suggested Dov Miller CC BY-SA 3.0
clientWidth instead of clientHeight in getWidth function
Feb 9, 2016 at 11:46 review Suggested edits
S Feb 9, 2016 at 12:16
Mar 13, 2015 at 4:00 comment added Andris ... 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)
Oct 15, 2014 at 19:13 history edited Travis CC BY-SA 3.0
Making code more efficient and easier to read.
Aug 17, 2014 at 5:04 comment added Emmanuel John This produces the right (or expected) results consistently compared to jQuery's implementation.
Jun 21, 2014 at 17:21 comment added David Aguirre Best answer because I dont have to include a 33k library for a simple redirect based on browser window width
Jun 24, 2009 at 14:36 history answered Travis CC BY-SA 2.5