2011-05-03 31 views
8

¿Cómo se puede obtener window.innerHeight en Internet Explorer. Gracias.Internet Explorer innerHeight

+0

posible duplicado de [? Como llegar navegador ancho con código javascript] (http://stackoverflow.com/questions/1038727/how-to-get-browser-width-using-javascript-code) –

Respuesta

7
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)]; 
    } 
} 
+3

¿No debería ser 'Math.min()' en lugar de 'Math.max()'? Al menos este parece ser el comportamiento que querrías en ie7 y ie8. –

0

La manera más fácil de usar jQuery. Here's algo de información detallada sobre el mismo.

1

Esto funciona de IE9:

document.body.clientHeight 
+3

innerHeight funciona bien en IE9. – kennebec

+0

Estoy buscando un camino en IE7 e IE8. –

+0

Lo sentimos, significa que debería funcionar en IE6 +. Solo lo probé en IE9. La solución de Kennebec es definitivamente más completa, aunque personalmente he usado document.documentElement antes. – Dan

1

Una sencilla solución de una línea:

var WinHeight = window.innerHeight || Math.max(document.documentElement.clientHeight, document.body.clientHeight); 
0

En IE9, window.innerHeight y document.body.clientHeight sólo funciona cuando el contenido es más alto que la ventana del documento.

Una solución confiable es utilizar las propiedades vw and vh css.

css (fácil) manera:

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

js manera:

// 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; 
};