WebBrowser控件中的AJAX检测 [英] AJAX detection in WebBrowser control
问题描述
我需要在WebBrowser控件中检测动态页面更新(由AJAX引起)。
我在C#(。Net 3.5)中有一个窗体,它嵌入了WebBrowser控件。此表单实现 IHTMLChangeSink ,以便我可以订阅通知事件。
I have a windows form in C# (.Net 3.5) which has WebBrowser control embedded. This form implements IHTMLChangeSink so that i can subscribe to Notify events.
这是代码:
private < font color ="#000000"size = 2> IHTMLChangeLog changeLog = null < font size = 2> ;
private IHTMLChangeLog changeLog = null;
私人 IMarkupContainer2 container2 = null ;
private IMarkupContainer2 container2 = null;
private IHTMLChangeSink changeSync = null ;
private IHTMLChangeSink changeSync = null;
private uint m_cookie;
public
public void Notify()
{
ProcessDocument();
}
在DocumentComplete事件中,我执行以下操作
//'获取当前MarkupContainer的句柄
//' Get a handle to the current MarkupContainer
container2 = null ;
changeLog = null ;
container2 = ( IMarkupContainer2 )webBrowser.Document.DomDocument;
//'创建更改日志
container2.CreateChangeLog( this , < font size = 2> out changeLog,1,1);
container2.RegisterForDirtyRange( this , out m_cookie);
container2.RegisterForDirtyRange(this, out m_cookie);
这适用于第一个网页,我为所有更改启动了Notify事件。但是当我去其他执行DocumentComplete的网页时,现在我不再获得Notify事件。
< font color ="#000000">
不知道我是不是我在做错什么?
感谢您的帮助,
Salim
推荐答案
每次导航时都会重新创建文档
在DocumentCompleted事件中获取新文档
The document is recreated everytime you navigate
obtain the new document in the DocumentCompleted event
这篇关于WebBrowser控件中的AJAX检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!