Internet Explorer innerHeight

How can you get window.innerHeight in Internet Explorer. Thank.

+8
javascript internet-explorer
May 03 '11 at 2:27 a.m.
source share
5 answers
window.getWinSize= function(){ if(window.innerWidth!= undefined){ return [window.innerWidth, window.innerHeight]; } else{ var B= document.body, D= document.documentElement; return [Math.max(D.clientWidth, B.clientWidth), Math.max(D.clientHeight, B.clientHeight)]; } } 
+7
May 03 '11 at 3:35
source share
โ€” -

This works in IE9:

 document.body.clientHeight 
+1
May 03 '11 at 2:37
source share

Simple single line solution:

 var WinHeight = window.innerHeight || Math.max(document.documentElement.clientHeight, document.body.clientHeight); 
+1
Jun 19 '15 at 1:34
source share

The easiest way to use jQuery. Below is the details of this.

0
May 03 '11 at 2:29
source share

In ie9, window.innerHeight and document.body.clientHeight only works when the content is larger than the document window.

A reliable solution is to use the vw and vh css properties.

css (simple) way:

 /* foce the content to be at 100% with css */ html, body { width: 100vw; height: 100vh; } 

js path:

 // make a fitted htmlelement and returns its size. var get_ie_size=function(){ var domtest = document.createElement('div'); domtest.style.display="block"; domtest.style.width="100vw"; domtest.style.height="100vh"; document.body.appendChild(domtest); var size = [domtest.offsetWidth,domtest.offsetHeight]; document.body.removeChild(domtest); return size; }; 
0
Jun 22 '15 at 21:35
source share



All Articles