Invoking DOM onmousedown event in a Webbrowser from Visual Basic 6

2.1k views Asked by At

I load an HTML document into a WebBrowser Control in Visual Basic 6.

There is a link something

<a href="something" onmousedown="return abc(this,'asd', 'AO',null,event)">

I want to invoke the onmousedown event programatically from VB

I've tried many things, including

doc.getElementsByTagName("a")(i).InvokeMember("MouseDown")
doc.getElementsByTagName("a")(i).RaiseEvent("OnMouseDown")
doc.getElementsByTagName("a")(i).MouseDown

but nothing seems to work.

1

There are 1 answers

3
MarkL On

I haven't tried to do this myself, but this vbcity post contains a description and some sample code for this. Scroll down to the last post on the first page of the thread.

http://vbcity.com/forums/t/37407.aspx

To boil the above post down to essentials, the members of the forms collection can be iterated to find the button which is then clicked.

With Me.WebBrowser1
    For n = 0 To .Document.Forms("formname").Length - 1
        If .Document.Forms("formname").Item(n).Value = "buttonvalue" Then
            .Document.Forms("formname").Item(n).Click
            Exit For
        End If
    Next n
End With

Replace 'formname' and 'buttonvalue' with appropriate values