Windows Phone WebBrowser:获取文档高度的正确方法

时间:2013-10-06 17:02:19

标签: javascript windows-phone-7 windows-phone-8 windows-phone internet-explorer-10

在我的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几乎是实际价值的一半?

谢谢大家

1 个答案:

答案 0 :(得分:0)

解决。
我试图在 DOM ready事件之前获取文档的高度,因此该值是错误的。

这里描述了知道何时加载DOM的可能解决方案之一:" javascript domready?"