简体   繁体   English

在jQuery中获取HTML文档的总高度

[英]Get the total height of HTML document in jQuery

I want to retrieve using jQuery the total height of my HTML document. 我想使用jQuery检索HTML文档的总高度。 I tried so many things, the max height I could get is the total height of the viewport, never taking into account if there was a vertical scrollbar or not. 我尝试了很多东西,我可以得到的最大高度是视口的总高度,如果有垂直滚动条则不考虑。 The following screen indicates what I want: 以下屏幕显示我想要的内容:

在此输入图像描述

$(document).height();  // return 898, which is only the height of the current visible part of the page
$(window).height();  // return 881
$("html").height();  // return 898
$("body").height();  // same
$("div#main").height();  // same
$(document).outerHeight();  // i'm wondering how can i do this ...

The tests was made on Firefox and Chrome browsers. 测试是在Firefox和Chrome浏览器上进行的。

Can someone explain if it's even possible to do this? 有人可以解释是否有可能这样做?

Apparently, even if my problem is not solved, it's bound to a weird behaviour of SharePoint. 显然,即使我的问题没有解决,它也必然会出现一种奇怪的SharePoint行为。 I'm trying to get the document height on a SharePoint 2013 page, but it will always return the viewport height. 我正在尝试在SharePoint 2013页面上获取文档高度,但它将始终返回视口高度。

You can use outerHeight() with you content wrapper you need to call this inside document ready 您可以将outerHeight()与内容包装器一起使用,您需要在文档内部调用此文件

example:- 例:-

// this return your all content height.
$(document).ready(function(){
   $("your all content wrapper name").outerHeight(); 
});

我也在努力解决这个问题,但你可能想尝试获得一个div包装器的高度,例如:

$("#DeltaPlaceHolderMain").height();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM