In all recent browser:
window.innerWidth // 1920
In Internet explorer 8
window.innerWidth // undefined
document.documentElement.clientWidth;
this is used for ie8 to get the client width
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;
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
.
Please note: .innerWidth method is not applicable to window and document objects; for these, use .width() instead.
jquery api documentation for .innerwidth()
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
Without jQuery you can try this to get height
and width
var myWidth = 0, myHeight = 0;
if (typeof (window.innerWidth) == 'number') { //Chrome
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { //IE9
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}