如何用JavaScript获取整个文档的高度?有些文档我无法获得文档的高度(将某些东西绝对定位在最下面)。此外,填充底部似乎在这些页面上什么都不做,但是在将返回高度的页面上执行。有关案例:http://fandango.comhttp://paperbackswap.com论范丹戈jQuery$(document).height();返回正确的值document.height返回0document.body.scrollHeight返回0平装书交换:jQuery$(document).height();TypeError:$(document)为空document.height返回不正确的值。document.body.scrollHeight返回不正确的值。注意:我有浏览器级别的权限,如果有什么窍门的话。
3 回答
繁星点点滴滴
TA贡献1803条经验 获得超3个赞
var body = document.body, html = document.documentElement;var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );
onload
慕斯王
TA贡献1864条经验 获得超2个赞
document.body.scrollHeight
<body>
document.documentElement.scrollHeight
隔江千里
TA贡献1906条经验 获得超10个赞
var B = document.body,
H = document.documentElement,
heightif (typeof document.height !== 'undefined') {
height = document.height // For webkit browsers} else {
height = Math.max( B.scrollHeight, B.offsetHeight,H.clientHeight, H.scrollHeight, H.offsetHeight );}Math.max($(document).height(), $(window).height())
添加回答
举报
0/150
提交
取消
