Internet Explorer innerHeight

2020-07-06 04:36发布

How can you get the window.innerHeight in internet explorer. Thanks.

5条回答
倾城 Initia
2楼-- · 2020-07-06 04:44

Easiest way it to use jQuery. Here's some detailed information on it.

查看更多
Deceive 欺骗
3楼-- · 2020-07-06 04:50
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)];
    }
}
查看更多
别忘想泡老子
4楼-- · 2020-07-06 04:50

A simple one line solution:

var WinHeight = window.innerHeight || Math.max(document.documentElement.clientHeight, document.body.clientHeight);
查看更多
家丑人穷心不美
5楼-- · 2020-07-06 05:02

This works in IE9:

document.body.clientHeight
查看更多
戒情不戒烟
6楼-- · 2020-07-06 05:03

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

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

css (easy) way :

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

js way :

// 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;
};
查看更多
登录 后发表回答