如何使用C#获取IE中文档的scrollHeight属性
我正在 C# 中使用 mshtml COM 组件来获取当前 Internet Explorer 中的 DOM 元素信息。 我的代码如下所示:
HTMLDocument document =....;
var offsetHeight = document.body.offsetHeight;// works fine
var scrollHeight = document.body.scrollHeight;//compiler error
HTMLDocument 类型来自 Microsoft.mshtml.dll COM 组件。 为什么 DOM 元素的scrollHeight属性可以通过javascript访问,而不能通过C#访问?如何通过另一个 .Net 应用程序获取正在运行的 IE 进程的滚动条状态?
I am using mshtml COM component in C# to get DOM element information in current Internet Explorer.
my code looks like this:
HTMLDocument document =....;
var offsetHeight = document.body.offsetHeight;// works fine
var scrollHeight = document.body.scrollHeight;//compiler error
The type HTMLDocument comes from the Microsoft.mshtml.dll COM component.
why the scrollHeight property of a DOM element, which can be accessed by javascript ,can't be accessed by C#? How can I get the scroll bar status of a running IE process by another .Net application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有人在做同样的事情,供将来参考。
在某些情况下,offsetHeight 被提到更好,因为它考虑了边框,但如果你说,想要滚动整个 IE 页面,你会想要使用滚动高度,如此处所述。
要检索滚动高度,您需要将 body 元素转换为具有此属性的 IHTMLTextContainer 接口:
希望这对某人有帮助。
For future reference if someone is doing this same thing.
The offsetHeight is mentioned to be better in some cases since it accounts for borders but if you say, want to scroll the entirety of an IE page you would want to use the scroll height as said here.
To retrieve the scroll height you need to cast the body element to the IHTMLTextContainer interface which has got this property:
Hope this helps someone.