Results 1 to 8 of 8

Thread: I need a Link in the WebBrowser control to run VB procedure

  1. #1

    Thread Starter
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265

    Angry I need a Link in the WebBrowser control to run VB procedure

    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?

  2. #2
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    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

  3. #3

    Thread Starter
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265
    Thanks Rye... that's what I ended up doing.

    VB Code:
    1. 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)
    2. If Left$(URL, 6) = "event:" Then
    3.     Select Case Mid(URL, 7)
    4.         Case "RunMyCode"
    5.             ' Put the code that you want to run here
    6.             Cancel = True
    7.     End Select
    8. End If
    9. 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>

  4. #4

    Thread Starter
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265
    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?

  5. #5
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    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.
    VB Code:
    1. If (pDisp is WebBrowser1.Object) Then
    2.     WebBrowser1.Document.All("username").Value = "what-ever"
    3. End If
    When you navigate to the page that has that textbox, "what-ever"
    will be displayed in the textbox.

  6. #6

    Thread Starter
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265
    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:
    1. 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?

  7. #7
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Your in the wrong event.

    No big deal, DownloadComplete and DocumentComplete look the same when choosing from a list. I make that mistake myself...

  8. #8

    Thread Starter
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265
    I guess I need to open my eyes! Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width