I have a WebBrowser control displaying a webpage. I want the Command1_Click procedure to be run when a user clicks on a specific link on the webpage. Is this possible?
Printable View
I have a WebBrowser control displaying a webpage. I want the Command1_Click procedure to be run when a user clicks on a specific link on the webpage. Is this possible?
Check this link out for sinking document events for the webbrowser. This should get you headed in the right direction
http://support.microsoft.com/support.../Q246/2/47.asp
Thanks Rye... that's what I ended up doing.
VB Code:
Private Sub brwWebBrowser_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean) If Left$(URL, 6) = "event:" Then Select Case Mid(URL, 7) Case "RunMyCode" ' Put the code that you want to run here Cancel = True End Select End If End Sub
Now... in the html put this:
Code:<HTML>
<BODY>
<A HREF="EVENT:RunMyCode">Click here</A> to run my VB code.
</BODY>
</HTML>
Ok... say I have a textbox in a form on my HTML page... how can I tell VB to put certain text in that box?
Look in the html code for the "name" of the textbox.
Let's say you do and the name is "username".
Now in the DocumentComplete Event code it something like this.
When you navigate to the page that has that textbox, "what-ever"VB Code:
If (pDisp is WebBrowser1.Object) Then WebBrowser1.Document.All("username").Value = "what-ever" End If
will be displayed in the textbox.
Thanks bloodeye... that worked.
But for some reason my WebBrowser control doesn't have that pDisp variable in the subroutine heading. Mine says:
VB Code:
Private Sub brwWebBrowser_DownloadComplete()
So I just didn't use the if statement and it seems to work fine (I did say On Error Resume Next)... that's why.
Any clue why I don't have that pDisp value?
Your in the wrong event. :rolleyes:
No big deal, DownloadComplete and DocumentComplete look the same when choosing from a list. I make that mistake myself...:p
I guess I need to open my eyes! Thanks.