1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

vb6 WebBrowser control

Discussion in 'Software Development' started by booknet, Sep 14, 2004.

Thread Status:
Not open for further replies.
Advertisement
  1. booknet

    booknet Thread Starter

    Joined:
    Sep 14, 2004
    Messages:
    2
    I use the following Code to find string in A HTMl in WebBrowser control, but
    if HTML support Frame then I get the error (run-time error "438"). any idea
    how to fix this error.
    Thanks,
    Harry

    Code:
          Public myfindFirst As Boolean
          Public oRange
    
    Private Sub cmdFind_Click()
        Dim sSearch As String
        If myfindFirst Then
            Set oRange = WebBrowser1.Document.body.createTextRange
            sSearch = txtFind.Text
            If oRange.FindText(sSearch) Then
              oRange.Select
              oRange.scrollIntoView
              cmdFind.Caption = "Find Next"
    
              myfindFirst = False
            Else
             MsgBox ("Search string " & txtFind.Text & " not found.")
            End If
        Else
            Call oRange.Move("character")
            sSearch = txtFind.Text
            If oRange.FindText(sSearch) Then
                oRange.Select
                oRange.scrollIntoView
            Else
                MsgBox ("Finished searching Document for string " & 
    txtFind.Text)
                cmdFind.Caption = "Find"
                myfindFirst = True
                Exit Sub
            End If
        End If
    
    End Sub
    
    
     
  2. Mosaic1

    Mosaic1

    Joined:
    Aug 17, 2001
    Messages:
    7,486
    If you are working with frames there is no document.body


    To test for the presence of frames:
    Code:
    Private Sub Command3_Click()
    Set frames = WebBrowser1.Document.getElementsByTagName("frame")
      
    If frames.length > 0 Then 'If there are frames
     For Each Frame In frames
       List1.AddItem Frame.LocationURL
     Next
    End If
    End Sub
    
    This example will get you the url for each frame and add them to a list box.

    Otherwise execute the other code.
     
  3. Mosaic1

    Mosaic1

    Joined:
    Aug 17, 2001
    Messages:
    7,486
    Here's something else to play with. This will put the html code of all frames for the currently loaded WebBrowser Document into a text box. You can use a variable or whatever.

    Code:
    Private Sub Command4_Click()
    Dim Cont As Object
    Dim sBody As String, k As Integer
    
    For k = 0 To WebBrowser1.Document.frames.length - 1 
    
    Set Cont = WebBrowser1.Document.frames(k).Document
    sBody = Cont.body.innerHTML ' or use innerTEXT  if you prefer.
    Text1.Text = Text1.Text & "NEXT" & vbCrLf & sBody & vbCrLf & vbCrLf & vbCrLf 
    Next
    End Sub
     
  4. booknet

    booknet Thread Starter

    Joined:
    Sep 14, 2004
    Messages:
    2
    yes, but how can I use these code to find A special text in webbrowser document (support Frame)?
     
  5. Mosaic1

    Mosaic1

    Joined:
    Aug 17, 2001
    Messages:
    7,486
    See if you can work with this instead. I haven't tried to find a string inside a frame. Search one frame at a time.

    Code:
    Dim range As Object
    Dim k as Integer
      
      For k = 0 To WebBrowser1.Document.frames.length - 1
    
       Set range = WebBrowser1.Document.frames(k).Document.body.createTextRange
    
    
    Add Search code.
    
    Next
      
       
     
  6. Mosaic1

    Mosaic1

    Joined:
    Aug 17, 2001
    Messages:
    7,486
    Or you could set something up to search only selected frames.
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/273759

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice