如何获得网络浏览器窗口的确切高度? [英] how to get exact height of body of the webbrowser window?

查看:57
本文介绍了如何获得网络浏览器窗口的确切高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取Web浏览器窗口主体的确切高度.我在谷歌搜索时尝试了innerHeight,clientHeight其他所有解决方案.但它们都没有给出确切的高度.我必须通过从这些函数提供的高度中减去一些值来调整高度?如何摆脱这个问题.我想我缺少了一些东西.请帮忙.

I want to get exact height of the body of webbrowser window. I tried innerHeight, clientHeight all other solutions which I get while googling. but none of them give exact height. I had to adjust the height by subtracting some value from the height provided by these functions?? How can get out of this problem. I think I'm missing some thing. please help.

谢谢

推荐答案

某些浏览器以不同的方式报告窗口高度 不同-特别是具有不同视口概念的移动浏览器.有时我会使用一个函数来检查几个不同的值,以最大的为准.例如

Some browsers report the window height incorrectly differently - particularly mobile browsers, which have a different viewport concept. I sometimes use a function to check several different values, returning whichever is the greatest. For example

function documentHeight() {
    return Math.max(
        window.innerHeight,
        document.body.offsetHeight,
        document.documentElement.clientHeight
    );
}

我只是研究了jQuery的工作方式,它确实使用了Math.max和一系列属性-但是它检查的列表与上面的示例稍有不同,并且因为我通常相信jQuery团队比我更擅长于此.这是非jQuery jQuery解决方案(如果有任何意义):

I just looked at how jQuery does it and it does indeed use Math.max and a series of properties - however the list it checks is slightly different to those in my example above, and since I usually trust the jQuery team to be better at this stuff than I am; here is the non-jQuery jQuery solution (if that makes any sense):

function documentHeight() {
    return Math.max(
        document.documentElement.clientHeight,
        document.body.scrollHeight,
        document.documentElement.scrollHeight,
        document.body.offsetHeight,
        document.documentElement.offsetHeight
    );
}

这篇关于如何获得网络浏览器窗口的确切高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆