javascript Internet Explorer 内部高度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5864467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 18:36:31  来源:igfitidea点击:

Internet Explorer innerHeight

javascriptinternet-explorer

提问by Shane Larson

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

如何在 Internet Explorer 中获取 window.innerHeight。谢谢。

采纳答案by kennebec

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

回答by Sebastián Grignoli

A simple one line solution:

一个简单的单行解决方案:

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

回答by Dan

This works in IE9:

这适用于 IE9:

document.body.clientHeight

回答by yorg

In ie9, window.innerHeightand document.body.clientHeightonly works when the content is higher than the document window.

在ie9中,window.innerHeightdocument.body.clientHeight只有在内容高于文档窗口时才起作用。

A reliable solution is to use the vwand vhcss properties.

一个可靠的解决方案是使用vwvhcss 属性。

css (easy) way :

css(简单)方式:

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

js way :

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

回答by ataddeini

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

使用 jQuery 的最简单方法。这里有一些关于它详细信息。