Hi.
I've created a generic DOM event handler in my C# BHO code as follows:
-----
public delegate void DHTMLEvent(IHTMLEventObj e);
/// Generic Event handler for HTML DOM objects.
/// Handles a basic event object which receives an IHTMLEventObj which
/// applies to all document events raised.
[ComVisible(true)]
public class DHTMLEventHandler
{
public DHTMLEvent Handler;
HTMLDocument Document;
public DHTMLEventHandler(mshtml.H
TMLDocumen
t doc)
{
this.Document = doc;
}
[DispId(0)]
public void Call()
{
Handler(Document.parentWin
dow.@event
);
}
}
----
I've used the code above to sucessfully create an event handler for the onclick event of the document element of the current webbrowser.
I now want to create an event handler to capture when the innerHTML property of a DIV tag contained in the document changes. I've done the following:
--------
IHTMLDocument3 doc2 = (IHTMLDocument3)((IWebBrow
ser2)pDisp
).Document
;
DHTMLEventHandler Handler2 = new DHTMLEventHandler(doc2 as mshtml.HTMLDocument);
Handler2.Handler += new DHTMLEvent(OnDocumentPrope
rtyChanged
);
doc2.onpropertychange = Handler2;
--------
I've then coded the event handler as follows:
---------
public void OnDocumentPropertyChanged(
IHTMLEvent
Obj evo)
{
IHTMLElement2 element = (IHTMLElement2)evo.srcElem
ent;
if (evo != null)
{
MessageBox.Show(evo.srcEle
ment.inner
HTML);
}
}
---------
This code seems to capture when a property changes, but it doesn't correctly reflect the source element that raised the event.
Can anyone help me with identifying the source element that raised the onpropertychanged event or suggest another way of capturing the change of a child DIV tags inner HTML property.
Thanks,
Peter
Start Free Trial