2

I got this code from this question (How to get document height and width without using jquery) :

width = Math.max(
    document.documentElement.clientWidth,
    document.body.scrollWidth,
    document.documentElement.scrollWidth,
    document.body.offsetWidth,
    document.documentElement.offsetWidth
);

How reliable is it? It doesn't seem to work as expected on Opera 12 - but that's rather old now.

Other than that browser it seems to be OK.

1 Answer 1

2

document.documentElement.clientWidth and window.innerWidth should work across all browsers (you can test here https://ryanve.com/lab/dimensions/). Opera 12 is 8 years old and not available for testing on https://browserstack.com so I wasn’t able to test.

FYI, if you care about the scrollbar width, check out these posts:

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.