有些文件我不能得到文件的高度(位置绝对在最底部)。此外,填充底部似乎在这些页面上不起任何作用,但在高度将返回的页面上起作用。相关案例:

http://fandango.com http://paperbackswap.com

在胡闹 jQuery的$(文档).height ();返回正确的值 文档。Height返回0 document.body.scrollHeight返回0

关于平装书互换: jQuery的$(文档).height ();TypeError: $(document)为空 文档。Height返回不正确的值 scrollheight返回错误的值

注意:我有浏览器级别的权限,如果有一些技巧在那里。


当前回答

我撒谎了,jQuery为两个页面返回正确的值$(document).height();…我为什么要怀疑它呢?

其他回答

使用吹码计算高度+滚动

var dif = document.documentElement.scrollHeight - document.documentElement.clientHeight;

var height = dif + document.documentElement.scrollHeight +"px";

2017年的正确答案是:

.height document.documentElement.getBoundingClientRect ()

与document.body.scrollHeight不同的是,该方法只考虑正文边距。 它还给出了分数高度值,这在某些情况下是有用的

我不知道如何确定高度,但你可以用这个在底部放一些东西:

<html>
<head>
<title>CSS bottom test</title>
<style>
.bottom {
  position: absolute;
  bottom: 1em;
  left: 1em;
}
</style>
</head>

<body>

<p>regular body stuff.</p>

<div class='bottom'>on the bottom</div>

</body>
</html>

正确添加引用

在我的情况下,我使用的是一个ASCX页面,而包含ASCX控件的aspx页面没有正确使用引用。 我只是粘贴下面的代码,它工作:

<script src="../js/jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
<script src="../js/jquery-1.3.2.js" type="text/javascript"></script>
<script src="../js/jquery-1.5.1.js" type="text/javascript"></script>

下面的跨浏览器代码计算body和html元素的所有可能高度,并返回找到的最大值:

            var body = document.body;
            var html = document.documentElement;
            var bodyH = Math.max(body.scrollHeight, body.offsetHeight, body.getBoundingClientRect().height, html.clientHeight, html.scrollHeight, html.offsetHeight); // The max height of the body

一个工作的例子:

function getHeight() { var body = document.body; var html = document.documentElement; var bodyH = Math.max(body.scrollHeight, body.offsetHeight, body.getBoundingClientRect().height, html.clientHeight, html.scrollHeight, html.offsetHeight); return bodyH; } document.getElementById('height').innerText = getHeight(); body,html { height: 3000px; } #posbtm { bottom: 0; position: fixed; background-color: Yellow; } <div id="posbtm">The max Height of this document is: <span id="height"></span> px</div> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br /> example document body content example document body content example document body content example document body content <br />