3

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
noway
  • 2,585
  • 7
  • 41
  • 61

1 Answers1

0

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

MarkL
  • 1,721
  • 1
  • 11
  • 22
  • This article is about handling events. OP wants to trigger events, which is exactly opposite. – GSerg Feb 05 '12 at 22:37
  • GSerg: you are correct - I read the question backwards. I have updated the answer. Thanks for the correction! – MarkL Feb 06 '12 at 15:18
  • Actually, doc.getElementsByID("submitbutton").Click works. However, the only event you can fire from the code with this way is "Click", I think. I cannot fire the mousedown event with this and above mentioned ways. – noway Feb 10 '12 at 15:51