精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
I am using the csEXwb control with Visual Basic 2005 .NET to trace user actions in the IE. I have a problem that I don't get any click events from the links on the page I am browsing. The first thing, I have done, was to define event handlers for click events after the document have been loaded. So I load a DOM after the document is completely loaded (e.istoplevel = true) and declare handlers to trace onclick events for HTML elements with the node name "A":
我现在在Visual Basic .NET 2005下用csEXwb控件,来追查在IE浏览器的用户操作。我有一个问题,我没有得到我浏览的页面上的链接的任何点击事件。在程序文档已经被加载后,我所做的第一件事,是为click事件定义事件处理。该文件是完全加载(e.istoplevel = TRUE)后,我打开一个DOM,并定义处理程序来跟踪HTML元素“A”的onclick事件。
Dim anchor As HTMLAnchorElementClass = _ CType(node, HTMLAnchorElementClass)
AddHandler anchor.HTMLAnchorEvents_Event_onclick, AddressOf HandleClick.
I expect to get call in the HandleCheck function each time I click on any link on the page, but I don't get any call at all.
我期望得到的HandleCheck功能,每次我点击页面上的任何链接调用,但我没有得到任何调用。
I have heard there are some complications when tracing events from COM objects in the VB code. What could be here wrong? I have been trying the same with the other event HTMLAnchorEvents2_Event_onclick, but get the same behaviour - no events fired.
我听说那里的VB代码跟踪从COM对象的事件时,有一定的并发症。在这里有什么错了吗?我一直在试图同与其他事件HTMLAnchorEvents2_Event的onclick,但得到了同样的行为 - 没有任何事件触发。
Here is an easier way to handle click events for A elements. Subscribe to document's OnClick event, catch OnClick event in your handler, examine the IHTMLEventObj.SrcElement ,which is an IHTMLElement.
这里有一个简单的方法来处理click事件对于A元素。订阅文档的OnClick事件,在您的处理程序赶上OnClick事件,检查IHTMLEventObj.SrcElement,这是一个IHTMLElement。
If IHTMLEventObj.SrcElement != null and IHTMLEventObj.SrcElement.tagName == "A" and IHTMLEventObj.SrcElement.getAttribute("name", 0) == "Desired name" and IHTMLEventObj.SrcElement.getAttribute("id", 0) == "Desired id" Then perform desired tasks.
Please refer to frmHTMLEditor.cs to see an example of how to subscribe to document events (frmHTMLeditor_Load event) and how to handle such events (IHTMLEventCallBack.HandleHTMLEvent event).
请参考frmHTMLEditor.cs看如何订阅文档事件为例(frmHTMLeditor_Load事件),以及如何处理此类事件(IHTMLEventCallBack.HandleHTMLEvent事件)。
Don't get any HTML events to be called back. Is it possible that VB.NET have some restrictions on using this callback technique?
这些我都做了,但还是没有得到任何HTML事件被召回。有没有可能是VB.NET对使用这种回调技术的一些限制?
I habe made the following steps:
我HABE作了如下步骤:
1. Declared the form implements the interface IfacesEnumsStructsClasses.IHTMLEventCallBack
2. Declared event handlers for DocumentComplete and BeforeNavigate2 events in the Form_Load
3. Set HTML events to call back in the Form_Load
Dim dispids() As Integer = { _ IfacesEnumsStructsClasses.HTMLEventDispIds.ID_ONKEYUP, _ IfacesEnumsStructsClasses.HTMLEventDispIds.ID_ONCLICK, _ IfacesEnumsStructsClasses.HTMLEventDispIds.ID_ONCONTEXTMENU} m_elemEvents.InitHTMLEvents( _ Me, _ dispids, _ IfacesEnumsStructsClasses.Iid_Clsids.DIID_HTMLElementEvents2) cEXWB1.NavToBlank()
4. Connected to HTML events in the DocumentComplete Dim webBrowser As IfacesEnumsStructsClasses.IWebBrowser2 = _CType(e.browser, IfacesEnumsStructsClasses.IWebBrowser2),Dim pBody As IHTMLDocument3 = webBrowser.Document m_elemEvents.ConnectToHtmlEvents(pBody.documentElement)
5. Disconnected from HTML events in the BeforeNavigate2 m_elemEvents.DisconnectHtmlEvents()
6. Implemented HandleHTMLEvent handler as simple as MsgBox("I am here") return True
I have meantime tested the same procedure (steps 1 .. 6) in C# and it seems to work accurate.
我曾同时测试了同样的过程(步骤1。6)在C#中,它似乎工作准确。
I have found the error. The reason was an ambiguous definition of the function,which implements HandleHTMLEvent handler in my code.
我发现了错误。原因是所述函数的模糊定义,在我的代码里,实现了HandleHTMLEvent 事件处理。