How Do I Get innerWidth in Internet explorer 8

Solution 1:

The innerWidth is supported by IE9 not IE8, you can do this insteaad:

var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;

The above line will get you the width from IE as well as other standard-compliant browsers.


If you use jQuery, $(window).innerWidth() will give you desired result in all browsers too.

Solution 2:

For getting this, I still use:

window.innerWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
window.innerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

But to imitate the real dom-getter take a look at this: https://stackoverflow.com/a/18136089/1250044

Solution 3:

for ie8 use

document.documentElement.clientWidth

Solution 4:

I know that the innerWidth might not be quite the same, but getBoundingClientRect could also be used in a similar capacity:

elem = document.documentElement.getBoundingClientRect();
width = elem.getBoundingClientRect().right - elem.getBoundingClientRect().left;

Solution 5:

You can get this information from IE 8 with

document.documentElement.clientWidth

Be advised that this value will not be exactly the same that IE 9 returns for window.innerWidth.