vb6 WebBrowser control

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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
 
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.
 
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
 

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)?
 
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
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Top