如何在Internet Explorer中获取窗口的innerHeight?谢谢。
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)];
}
}
Math.min()
而不是Math.max()
,至少这似乎是你想要的行为。 - Jonas Äppelgran一个简单的一行解决方案:
var WinHeight = window.innerHeight || Math.max(document.documentElement.clientHeight, document.body.clientHeight);
这在IE9中有效:
document.body.clientHeight
/* foce the content to be at 100% with css */
html, body {
width: 100vw;
height: 100vh;
}
JS之道:
// 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;
};