【发布时间】:2013-10-13 05:41:40
【问题描述】:
在我的 Windows Phone 8 应用程序中,我有一个 WebBrowser 控件 (Internet Explorer 10)。我需要获取加载到其中的文档的总高度。
我必须只使用 Javascript(没有 jQuery),所以我现在使用的是这段代码(从 jQuery 源代码中提取):
documentHeight = Math.max(
document.body['scrollHeight'],
document.documentElement['scrollHeight'],
document.body['offsetHeight'],
document.documentElement['offsetHeight'],
document.documentElement['clientHeight']
);
对于长页面,例如,我得到6000 pixels。为了检查结果是否正确,我手动滚动到页面底部并获得document.documentElement.scrollTop 值。
在这种情况下,返回的值为11000 pixels,应该是文档高度的正确值。
那么为什么 documentHeight 几乎是真实值的一半呢?
谢谢大家
【问题讨论】:
-
您是否在 DOM Ready 事件后检查文档高度?
-
不,这就是问题所在。我昨天在提交问题后意识到了这一点。还是谢谢你:)
-
您可以将其作为答案,并将其设为“已接受”:)
标签: javascript windows-phone-7 windows-phone-8 windows-phone internet-explorer-10