Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

I was wondering if it is possible to retrieve the complete HTML source (like the View Source option in the internet explorer) of a website using the WebBrowser control in VS2005?

 

Thanks,

 

Thei

Posted

Yes marble_eater, thank you!

 

Perhaps you can also help me with the following? Is it possible to find a certain word within a document (using the same WebBrowser control) and select that word using code in order to use the ExecCommand method?

Posted

I've solved the problem. See the code below (object wb = WebBrowser control).

 

       Dim strSource As String = wb.DocumentText.ToString
       Dim intPos As Integer = Strings.InStr(strSource, "</title>", CompareMethod.Text)

       If intPos <> 0 Then
           Dim strTempSource As String = String.Empty

           strTempSource = Strings.Mid(strSource, 1, intPos - 1) & "</title><script language='JavaScript'>function SelectText(pValue) {var r = document.body.createTextRange(); var t = r.findText(pValue); if (t == true) {r.select();} return t;}</script>" & Strings.Mid(strSource, intPos + 8, Strings.Len(strSource)) '+ 8 is length of text </title>.

           wb.Document.Write(strTempSource)

           Dim Cnt As Integer = UBound(arrFind) + 1
           Dim i As Integer

           For i = 1 To Cnt
               Dim arrObj(0) As Object
               Dim bolSuccess As Boolean

               arrObj(0) = CObj(New String(arrFind(i - 1).ToString))

               With wb.Document
                   bolSuccess = .InvokeScript("SelectText", arrObj)

                   If bolSuccess = True Then
                       .ExecCommand("ForeColor", False, "#FF0000")
                       .ExecCommand("BackColor", False, "#FFFF00")
                       .ExecCommand("Unselect", False, Nothing)
                   End If
               End With
           Next
       End If

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...