使用 IHTMLDocuments 1、2、3 和 4
我在当前项目中使用网络浏览器,目前我在设计模式下使用它以使其可编辑等。我当前使用的代码是:
WebBrowser.Document.DomDocument as IHTMLDocument2
IHTMLDocument2、3 或 4 实际上是什么? 我还发现,在识别文档中的当前选择范围时,range.text.replace 方法的工作方式与 string.replace 不同。
有人可以向我解释 IHTMLDocuments 和 IHTMLTxtRange 的基本功能吗?
I am using a web browser in my current project and currently I'm using it in design mode to make it editable etc. The code I am currently using is:
WebBrowser.Document.DomDocument as IHTMLDocument2
What actually is an IHTMLDocument2, 3 or 4? I have also found that when identifying a current selection range in the document, the range.text.replace method is not working the same way that a string.replace does.
Can anybody explain to me the basic functionality of the IHTMLDocuments and the IHTMLTxtRange please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IHTMLDocument 是一个接口,本质上是一个“牢不可破”的契约,代表实现它的对象将提供的内容。
在迁移到新版本的代码时更改接口会破坏该契约,进而破坏依赖于该契约的代码。
假设您创建:
一年后您需要添加 Property2 但无法更改界面。 因此,解决这个问题的一种方法是创建:
然后使用正在实现 IMyInterface 的旧类:
然后您将不会破坏旧的合同,但可以在代码中使用新的接口,例如:
这就是微软所做的。 IHTMLDocument 所在的mshtml 库是一个COM 库,而COM 严重依赖于接口。 因此,随着库的发展,微软添加了越来越多的接口来公开更新的功能/代码。
IHTMLTxtRange 是更常用的 TextRange 对象。
它公开了一系列用于解析文本“片段”或“范围”的功能。
http://www.webreference.com/js/column12/trmethods.html
IHTMLDocument is an interface which is essentially an "unbreakable" contract that represents what the object that implements it will provide.
Changing the interface when moving to a new version of the code would break that contract and in turn break the code that is relying on that contract.
Suppose you create :
A year later you need to add Property2 but you cannot change your interface. So one way around that is to create:
and then with your old Class that is implementing IMyInterface :
Then you will not break the older contract but can use the new interface in code such as:
So that is what Microsoft did. The mshtml library that IHTMLDocument is in is a COM library and COM rely's heavily on interfaces. So as the library evolved Microsoft added more and more Interfaces to expose the newer functionality/code.
IHTMLTxtRange is an interface for the more commonly used TextRange object.
It exposes a bunch of functionality for parsing text "Fragments" or "Ranges".
http://www.webreference.com/js/column12/trmethods.html