2

I've got a page that sets a lot of css properties using javascript and it uses $(window).width() to determine the page width. Among other things, it sets some div widths to be the full width of the page using that method. A It's done this way because a lot of the other calculations are done in javascript.

Anyway, I'm switching to a different navigation style and I set the body's overflow-y to be hidden. Unfortunately, now that the scrollbar has disappeared I'm left with a lovely white bar at the side of my page (in every browser I've tried) that is exactly the width of the scroll bar. Without specifically calculating the width of the scroll bar, which can get messy, how can I just get the width of the full browser including the scroll bar?

Thanks!

EDIT: It was an order of operations issue, I was being an idiot. Sorry!

Mr. Lavalamp
  • 1,860
  • 4
  • 17
  • 29
  • Try using $('body').width() if your body is set to 100% – ntgCleaner May 28 '13 at 21:50
  • That didn't work either, unfortunately. – Mr. Lavalamp May 28 '13 at 21:58
  • if you set `html, body { overflow-y: hidden; }` does it resolve? I've found certain settings that reset best with targeting both `html` and `body`. So is the question how to GET the width, or how to PREVENT that white bar? – Eli Gassert May 28 '13 at 21:59
  • 2
    Maybe it has to do with the order of operations... Can you set the body's overflow-y to hidden **BEFORE** you do the rest of your sizing? – jahroy May 28 '13 at 22:03
  • I just found the problem. I apologize for wasting everyone's time, as it WAS an order of operations thing. – Mr. Lavalamp May 28 '13 at 22:04
  • Possible duplicate of [How to get screen width without (minus) scrollbar?](http://stackoverflow.com/questions/8339377/how-to-get-screen-width-without-minus-scrollbar) – Bengi Besçeli Aug 02 '16 at 08:54

2 Answers2

3

window.outerWidth

The outerWidth property sets or returns the outer width of a window, including all interface elements (like toolbars/scrollbars).

http://www.w3schools.com/jsref/prop_win_outerheight.asp

seanjacob
  • 2,238
  • 1
  • 22
  • 25
0

use document instead

$(document).width()
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188