Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Controls
  New Posts New Posts RSS Feed - WebBrowser
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

WebBrowser

 Post Reply Post Reply
Author
Message
SteveStraley View Drop Down
Groupie
Groupie


Joined: 25 November 2005
Status: Offline
Points: 46
Post Options Post Options   Thanks (0) Thanks(0)   Quote SteveStraley Quote  Post ReplyReply Direct Link To This Post Topic: WebBrowser
    Posted: 20 May 2011 at 8:20pm
Hi,

Does anyone know how, within the AxWebBrowser control, to capture a selected section of text displayed within the control?

Thanks,

Steve
Back to Top
jpcoffeyXXX View Drop Down
Groupie
Groupie


Joined: 16 August 2005
Location: United States
Status: Offline
Points: 31
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpcoffeyXXX Quote  Post ReplyReply Direct Link To This Post Posted: 19 June 2012 at 3:10pm
Steve, the easy answer is,

Private Function RetrieveFrameSelectedTextEasy(wb As WebBrowser) As String
    Dim oDoc As HTMLDocument, tr As IHTMLTxtRange

    Set oDoc = wb.Document
    If LCase$(oDoc.selection.Type) = "text" Then
        Set tr = oDoc.selection.createRange
        RetrieveFrameSelectedText = tr.Text
        Set tr = Nothing
    End If
    Set oDoc = Nothing
End Function


However, in many cases, there are several iFrames on the page and you do not know which iFrame may have selected text.  In this case you would need to use the following,

Private Function RetrieveFrameSelectedText(wb As WebBrowser) As String
    Dim pContainer As olelib.IOleContainer
    Dim pEnumerator As olelib.IEnumUnknown
    Dim pUnk As olelib.IUnknown
    Dim pBrowser As shdocvw.IWebBrowser2
    '======================================
    Dim oDoc As HTMLDocument
    Dim tr As IHTMLTxtRange

    RetrieveFrameSelectedText = vbNullString
    Set pContainer = wb.Document
    ' Get an enumerator for the frames
    If pContainer.EnumObjects(OLECONTF_EMBEDDINGS, pEnumerator) = 0 Then
        Set pContainer = Nothing
        ' Enumerate all the frames
        Do While pEnumerator.Next(1, pUnk) = 0
            On Error Resume Next   'JPC - Edanmo's error handler
            ' Clear errors
            Err.Clear
            ' Get the IWebBrowser2 interface
            Set pBrowser = pUnk
            If Err.Number = 0 Then
                On Error GoTo 0
                'Debug.Print "Private Sub EnumFrames Frame URL: " & pBrowser.LocationURL

                Set oDoc = pBrowser.Document
                If LCase$(oDoc.selection.Type) = "text" Then
                    Set tr = oDoc.selection.createRange
                    RetrieveFrameSelectedText = tr.Text
                    Set tr = Nothing
                    'Don't look for anymore selected text
                    Exit Do
                End If
            End If
        Loop
        Set oDoc = Nothing
        Set pEnumerator = Nothing
    End If
End Function


It requires a reference to Edanmo's type library "OLELIB.TLB - OLE interfaces & functions v1.7" at the top of the page at

http://www.mvps.org/emorcillo/en/code/vb6/index.shtml

Hope this helps.

Sincerely,


John Coffey





Back to Top
McKloony View Drop Down
Senior Member
Senior Member
Avatar

Joined: 09 January 2007
Location: Germany
Status: Offline
Points: 340
Post Options Post Options   Thanks (0) Thanks(0)   Quote McKloony Quote  Post ReplyReply Direct Link To This Post Posted: 17 July 2012 at 5:14am
Is it also possible so save the content of a Webbrowser control als MHT or HTML File?
Product: Xtreme SuitePro (ActiveX) 16.2.5

Platform: XP / Windows 7

Language: Visual Basic 6.0 SP6
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.250 seconds.