I have this problem: I need to be able to catch changed in DOM elements in a page that I am loading in a Visual Basic webBrowser control. Normally in JavaScript in Firefox I would do something like this: element[0].childNodes[1].addEventListener("DOMAttrModified", functionX, true); where element[0] is the element that I need monitored and child[1] is the 2nd child for this element that has its text value changed which I need to catch when it ch开发者_如何学Canges, while functionX is the function/sub that I want to trigger everytime there is a change in element[0].childNodes[1].
I can do this easily in JavaScript but I am having a terrible time implementing this in Visual Basic 2010 in a webbrowser control that I use to implement a browser.
I know that there is something like Dim del As New EventHandler(AddressOf Me.CallGlobalJSMethod) but I am having a difficult time implementing this practically. Does anyone have any idea how this can be done practically?
Update: I am opening a page in a webbrowser control in VB2010 like this: WebBrowser1.Navigate(address.Text) then monitor the page. On this webpage there is a text field with id "ctrlid". This control's text property changes periodically. I need to catch the event when changes and react to it.
I asked this question 3 wks ago. I did figure out the answer meanwhile and I am documenting it here, in case someone else needs help. The problem was with the OnChange
event. The correct event trigger method is OnPropertyChange
for the webbrowser control to fire up events on changes for elements hosted on its navigated to page. This is a working example which I am pasting from a different VB forums where I asked the same question and finalized the answer:
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Dim doc As HtmlDocument = WebBrowser1.Document
Dim aC As HtmlElement = doc.GetElementById("previewclock")
Try
If aC Is Nothing Then Return
aC.AttachEventHandler("onpropertychange", AddressOf SomethingChanged)
Catch
End Try
and then a separate sub routine where the 'fired' event is processed:
Private Sub SomethingChanged(ByVal sender As Object, ByVal e As EventArgs)
'MsgBox("Event was captured!")
Console.WriteLine(Now.ToLongTimeString & ":" & "Changed")
End Sub
精彩评论