I use the following expression in JavaScript to get a screen width that seems to work fine, except that it contains the width of the vertical scrollbar when scrolling.
var wMax = Math.max(document.documentElement.clientWidth, window.innerWidth || 0)
Question . How can I change the above expression for the browser so that it displays the width of the screen, excluding the vertical scroll bar? I need to use JavaScript for this, not jQuery.
UPDATE 1:
I found the following cross-browser expression to get the width excluding the vertical scrollbar.
var wMax = Math.min(document.documentElement.clientWidth, window.innerWidth
|| screen.width);
- I used Math.min instead of Math.max, so any width was less than the width
- and also use screen.width instead of 0 in the original expression, since screen.width will always be the maximum width in this case for all browsers, since it will always include scroll bars.
source
share