WebBrowser control - tutorial/reference available?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    WebBrowser control - tutorial/reference available?

    Hi all.

    Can someone please point me to a simple tutorial or sample on how to use the WebBrowser control (or more specifically, how to work with the Document it returns)?

    I've been searching TheScripts and the rest of the internet, and the MSDN Library, and can't seem to find anything useful (though did find lots which wasn't). I even tried (briefly) reading up on the Document Object Model at Wikipedia and W3C, but haven't understood very much as yet.

    All I want is the basics on how to work with it in my code. I can use Navigate to go to an address, but have no idea how to do anything with the page that is returned. For example, how do I access (or simulate the user clicking on) a link? I can't even find the links - the brief examples given in the MSDN Library simply don't work.

    If I can just get a foot in the door, I'm sure I can take it from there.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Ahah!

    I think I'm finally starting to take some baby-steps. I had been getting 0 for the number of links, anchors, couldn't seem to find anything. I've just changed my testing URL to TheScripts instead of local intranet page, and suddenly there are 207 links. :)

    Now maybe I can start to get somewhere...

    (Could still do with that reference/sample/tutorial, though.)

    Comment

    • Dököll
      Recognized Expert Top Contributor
      • Nov 2006
      • 2379

      #3
      Geez, you're right, not much out there about this. There has to be something though, my professor attempted to teach us this, ages ago it seems. Too early in the going I was drawing a blank. I am going to go noodle with this one, I have a project for work, in fact, the only option is to convert VB to Java, too easy. Once I hear from my professor, I will relay info here; if you have not yet reached your goal. It's vastly interesting, please push on...

      Comment

      • Dököll
        Recognized Expert Top Contributor
        • Nov 2006
        • 2379

        #4
        It's likely you've seen this: http://msdn.microsoft. com/library/default.asp?url =/workshop/browser/webbrowser/tutorials/forward.asp

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by Dököll
          It's likely you've seen this: http://msdn.microsoft. com/library/default.asp?url =/workshop/browser/webbrowser/tutorials/forward.asp
          No, I hadn't until now. Thanks a lot for that.

          I have managed to piece together a little test program which (so far) loads a web page, lists the links in it, and click one for you. That's plenty to build on. But I'll definitely be giving the tutorial a once-over.

          Comment

          • ebhammer
            New Member
            • Feb 2007
            • 1

            #6
            Hey Killer, any chance you can share that code with me please?



            Originally posted by Killer42
            No, I hadn't until now. Thanks a lot for that.

            I have managed to piece together a little test program which (so far) loads a web page, lists the links in it, and click one for you. That's plenty to build on. But I'll definitely be giving the tutorial a once-over.

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by ebhammer
              Hey Killer, any chance you can share that code with me please?
              Ok, but it's in a very ugly state so far. This is what is in the form...[PHP]Option Explicit
              DefLng A-Z

              Private Sub Form_Load()
              CurrentState = "01 STARTING"
              Dim WDYWTGT As String
              WDYWTGT = InputBox("Where do you want to go today?", , "http://www.thescripts. com")
              If WDYWTGT <> "" Then
              CurrentState = "02 NAVIGATING"
              Me.Caption = "Navigating to " & WDYWTGT
              WebBrowser1.Vis ible = True
              WebBrowser1.Nav igate WDYWTGT
              Else
              End
              End If
              End Sub

              Private Sub Form_Resize()
              WebBrowser1.Mov e 0, 0, Me.ScaleWidth, Me.ScaleHeight
              End Sub



              Private Sub WebBrowser1_Doc umentComplete(B yVal pDisp As Object, URL As Variant)
              Dim I As Long
              Debug.Print "DocumentComple te"
              Me.Caption = "Examining document"
              Select Case CurrentState
              Case "02 NAVIGATING"
              CurrentState = "04 EXTRACTING LINKS"
              Load Dialog
              DoEvents
              With WebBrowser1.Doc ument
              For I = 0 To .Links.Length - 1
              Dialog.List1.Ad dItem .Links(I).HREF
              Next
              End With
              CurrentState = "05 WAITING"
              Dialog.Show vbModal
              Case "06 CLICKED"
              CurrentState = "07 DONE"
              MsgBox "Successful ly navigated to selected link"
              End
              End Select

              End Sub

              Private Sub WebBrowser1_Nav igateComplete2( ByVal pDisp As Object, URL As Variant)
              'MsgBox "NavigateComple te2"
              Beep
              End Sub

              Private Sub WebBrowser1_Nav igateError(ByVa l pDisp As Object, URL As Variant, Frame As Variant, StatusCode As Variant, Cancel As Boolean)
              If CurrentState = "02 NAVIGATING" _
              Or CurrentState = "06 CLICKED" Then
              CurrentState = "03 CRASHED"
              MsgBox "NavigateEr ror"
              End
              End If
              End Sub[/PHP]And in a separate module...
              Code:
              Option Explicit
              DefLng A-Z
              
              Public CurrentState As String
              
              Public Const navOpenInNewWindow As Long = 2
              Public Const navNoReadFromCache As Long = 4
              Public Const navNoWriteToCache As Long = 8
              Then there is another form called Dialog which just contains a listbox List1 and buttons OKbutton and CancelButton. Form caption is Document contains the following links - please click one...

              Comment

              Working...