Page 1 of 4 1234 LastLast
Results 1 to 40 of 135

Thread: Webbrowser Control Tip and Examples

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Cool Webbrowser Control Tip and Examples

    Webbrowser control

    Since I have been seen lately many people asking questions about the webbrowser control.

    First of all the webbrowser control is not one of the controls that come by default in the control box. All you have to do to add it there is to press Ctrl + T key or (Project -> Components using the menu). Once in the components select window scroll down and check the box next to “Microsoft Internet Controls” and click ok.

    Examples:
    • Navigating to a site
    • Popup browser using your own form
    • Check if word/string is found on the page
    • Making page on startup
    • Regular Browser Functions
    • Advanced browser functions
    • Changing web browser’s Font Size
    • Disabling functions appropriately (Back/Forward)
    • Disabling functions appropriately (page setup/print preview/print setup)
    • Removing Right Click Menu From the browser control
    • Grab all links on the page
    • Save Page
    • Open Page
    • Auto Submit
    • Using A ProgressBar With The Webbrowser
    • Setting a Control in a Webbrowser to focus
    • Checkbox in a page, how to control it
    • Custom Right Click Menu


    Navigating to a site:
    Navigating to a site...
    VB Code:
    1. WebBrowser1.Navigate "www.google.com"
    Opening a popup window with your app
    If the user go to a site where a new page needs to come in a new browser this code is made to open the target site in a new form.
    VB Code:
    1. Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
    2. Dim frm As Form1
    3. Set frm = New Form1
    4. Set ppDisp = frm.WebBrowser1.Object
    5. frm.Show
    6. End Sub
    Check if word/string is found on the page
    This code will let you check the page for a word or a sentence.
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim strfindword As String
    3.         strfindword = InputBox("What are you looking for?", "Find", "") ' what word to find?
    4.             If WebPageContains(strfindword) = True Then 'check if the word is in page
    5.                 MsgBox "The webpage contains the text" 'string is in page
    6.             Else
    7.                 MsgBox "The webpage doesn't contains the text" 'string is not in page
    8.             End If
    9. End Sub
    10. Private Function WebPageContains(ByVal s As String) As Boolean
    11.     Dim i As Long, EHTML
    12.     For i = 1 To WebBrowser1.Document.All.length
    13.         Set EHTML = _
    14.         WebBrowser1.Document.All.Item(i)
    15.  
    16.  
    17.         If Not (EHTML Is Nothing) Then
    18.             If InStr(1, EHTML.innerHTML, _
    19.             s, vbTextCompare) > 0 Then
    20.             WebPageContains = True
    21.             Exit Function
    22.         End If
    23.     End If
    24. Next i
    25. End Function
    26. Private Sub Form_Load()
    27.     WebBrowser1.Navigate2 "www.msn.com"
    28. End Sub
    Making page on startup
    This code show you how to make a page and show it on event.
    VB Code:
    1. Private Sub Form_Load()
    2.     WebBrowser1.Navigate "about:blank"
    3. End Sub
    4.  
    5. Private Sub Command1_Click()
    6.     Dim HTML As String
    7.         '----------The HTML CODE GOES FROM HERE AND DOWN----------
    8.     HTML = "<HTML>" & _
    9.             "<TITLE>Page On Load</TITLE>" & _
    10.             "<BODY>" & _
    11.             "<FONT COLOR = BLUE>" & _
    12.             "This is a " & _
    13.             "<FONT SIZE = 5>" & _
    14.             "<B>" & _
    15.             "programmatically " & _
    16.             "</B>" & _
    17.             "</FONT SIZE>" & _
    18.             "made page" & _
    19.             "</FONT>" & _
    20.             "</BODY>" & _
    21.             "</HTML>"
    22.             '----------The HTML CODE GOES HERE AND ABOVE----------
    23.     WebBrowser1.Document.Write HTML
    24. End Sub
    Regular Browser Functions
    This are the basic internet browser's functions.
    VB Code:
    1. Private Sub Command1_Click(Index As Integer)
    2. On Error Resume Next ' just in case there is no page back or forward
    3.                     'I showed how to disabel them if you scroll down more
    4.     Select Case Index
    5.         Case 0 'Go Back Button
    6.             WebBrowser1.GoBack 'Go Back one Page
    7.         Case 1 'Go Forward Button
    8.             WebBrowser1.GoForward 'Go Forward one Page
    9.         Case 2 'Stop Button
    10.             WebBrowser1.Stop 'stop page
    11.         Case 3 'Refresh Button
    12.             WebBrowser1.Refresh 'refresh page
    13.         Case 4 'Go Home Button
    14.             WebBrowser1.GoHome 'Go to home page
    15.         Case 5 'Search Button
    16.             WebBrowser1.GoSearch 'Search
    17.     End Select
    18. End Sub
    Advanced Browser Functions
    This are the more complex browser functions like print and page Properties.
    VB Code:
    1. Private Sub Command1_Click() 'Print Button
    2.     WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT 'Show Print Window
    3. End Sub
    4. Private Sub Command2_Click() 'Print Preview Button
    5.     WebBrowser1.ExecWB OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DODEFAULT 'Show Print Preview Window
    6. End Sub
    7. Private Sub Command3_Click() 'Page Setup Button
    8.     WebBrowser1.ExecWB OLECMDID_PAGESETUP, OLECMDEXECOPT_DODEFAULT 'Show Page Setup Window
    9. End Sub
    10. Private Sub Command4_Click() 'Page Properties Button
    11.     WebBrowser1.ExecWB OLECMDID_PROPERTIES, OLECMDEXECOPT_DODEFAULT 'Show Page Properties Window
    12. End Sub
    13. Private Sub Form_Load()
    14.     WebBrowser1.Navigate "www.google.com"
    15. End Sub
    Changing web browser’s Font Size
    This Code shows you how to change the page font size, just like internet explorer View -> Text Size Menu
    VB Code:
    1. Private Sub Command1_Click() ' Smallest Button
    2. On Error Resume Next
    3.     WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(0), vbNull
    4. End Sub
    5. Private Sub Command2_Click() 'Small Button
    6. On Error Resume Next
    7.     WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(1), vbNull
    8. End Sub
    9. Private Sub Command3_Click() 'Medium Button
    10. On Error Resume Next
    11.     WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(2), vbNull
    12. End Sub
    13. Private Sub Command4_Click() 'Large Button
    14. On Error Resume Next
    15.     WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(3), vbNull
    16. End Sub
    17. Private Sub Command5_Click() 'Largest Button
    18. On Error Resume Next
    19.     WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(4), vbNull
    20. End Sub
    21. Private Sub Form_Load()
    22.     WebBrowser1.Navigate2 "www.google.com"
    23. End Sub
    Disabling functions appropriately (Back/Forward)
    This code shows you how to appropriately disable the back and forward button.
    VB Code:
    1. Private Sub Command1_Click() 'Go Back Button
    2.     WebBrowser1.GoBack 'Go Back
    3. End Sub
    4. Private Sub Command2_Click() 'Go Forward Button
    5.     WebBrowser1.GoForward 'Go Forward
    6. End Sub
    7. Private Sub Form_Load()
    8.     WebBrowser1.Navigate "www.google.com"
    9. End Sub
    10. Private Sub WebBrowser1_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)
    11.     Select Case Command
    12.         Case 1 'Forward
    13.             Command2.Enabled = Enable
    14.         Case 2 'Back
    15.             Command1.Enabled = Enable
    16.     End Select
    17. End Sub
    Disabling functions appropriately (page setup/print preview/print setup)
    This code shows you how to appropriately disable the page setup or print setup.
    VB Code:
    1. Private Sub Command1_Click() 'Print Button
    2.     WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT 'Show Print Window
    3. End Sub
    4. Private Sub Command2_Click() 'Print Preview Button
    5.     WebBrowser1.ExecWB OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DODEFAULT 'Show Print Preview Window
    6. End Sub
    7. Private Sub Command3_Click() 'Page Setup Button
    8.     WebBrowser1.ExecWB OLECMDID_PAGESETUP, OLECMDEXECOPT_DODEFAULT 'Show Page Setup Window
    9. End Sub
    10. Private Sub Form_Load()
    11.     WebBrowser1.Navigate "www.google.com"
    12. End Sub
    13. Public Function Enable_or_Disable()
    14.     If WebBrowser1.QueryStatusWB(OLECMDID_PRINT) = 0 Then
    15.         Command1.Enabled = False
    16.     Else
    17.         Command1.Enabled = True
    18.     End If
    19.     If WebBrowser1.QueryStatusWB(OLECMDID_PRINTPREVIEW) = 0 Then
    20.         Command2.Enabled = False
    21.     Else
    22.         Command2.Enabled = True
    23.     End If
    24.  
    25.     If WebBrowser1.QueryStatusWB(OLECMDID_PAGESETUP) = 0 Then
    26.         Command3.Enabled = False
    27.     Else
    28.         Command3.Enabled = True
    29.     End If
    30. End Function
    31. Private Sub WebBrowser1_BeforeNavigate2 _
    32.                     (ByVal pDisp As Object, _
    33.                                 URL As Variant, _
    34.                                 Flags As Variant, _
    35.                         TargetFrameName As Variant, _
    36.                                 PostData As Variant, _
    37.                                     Headers As Variant, _
    38.                                         Cancel As Boolean)
    39.     Enable_or_Disable
    40. End Sub
    41. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    42.     Enable_or_Disable
    43. End Sub
    Removing Right Click Menu From the browser control
    So you need to remove the right click menu from the control, right? well there are more then two ways one of them, which i knew but i won't bother telling is using lots of hooking, waist of thime since all you have to do is download a simple helper file.
    First you need to go to http://support.microsoft.com/kb/q183235/ and download the WBCustomizer.dll. once done go to the"Project Menu" and click on "Refrences" Click on browse and add the 'WBCustomizer.dll' to you app. once done just add this simple code.
    VB Code:
    1. Option Explicit
    2.     Dim CustomWB As WBCustomizer 'Deceler the CustomWB
    3. Private Sub Form_Load()
    4.    Set CustomWB = New WBCustomizer
    5.    With CustomWB
    6.       .EnableContextMenus = False 'Disable The Menu
    7.       .EnableAllAccelerators = True
    8.      
    9.       Set .WebBrowser = WebBrowser1
    10.    End With
    11.     WebBrowser1.Navigate "www.google.com"
    12.         CustomWB.EnableContextMenus = False
    13. End Sub
    Last edited by wiz126; Mar 23rd, 2006 at 03:46 PM.
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  2. #2

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Webbrowser Control Tip and Examples

    Grab all links on the page
    This code shows how to grab and list all the links on a page, this can be used a spider software for a search engine site.
    In order to get this code to load you must add the "Microsoft HTML Object Library" into your app refrences.
    VB Code:
    1. Option Explicit
    2. Private Sub Form_Load()
    3.     WebBrowser1.Navigate "www.vbforums.com"
    4. End Sub
    5. Private Sub WebBrowser1_DownloadComplete()
    6.     'you must add the "Microsoft HTML Object Library"!!!!!!!!!
    7.     Dim HTMLdoc As HTMLDocument
    8.         Dim HTMLlinks As HTMLAnchorElement
    9.             Dim STRtxt As String
    10.     ' List the links.
    11.     On Error Resume Next
    12.         Set HTMLdoc = WebBrowser1.Document
    13.             For Each HTMLlinks In HTMLdoc.links
    14.                 STRtxt = STRtxt & HTMLlinks.href & vbCrLf
    15.             Next HTMLlinks
    16.         Text1.Text = STRtxt
    17. End Sub
    You can add this code in order to log this files.
    VB Code:
    1. Open "C:\Documents and Settings\[YOU USERNAME]\Desktop\link log.txt" For Append As #1
    2. Print #1, STRtxt
    3. Close #1
    Save Page
    This code shows you how to save the browser's page.
    VB Code:
    1. Option Explicit
    2. Private Sub Command1_Click()
    3. WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT
    4. End Sub
    5. Private Sub Form_Load()
    6. WebBrowser1.Navigate2 "www.google.com"
    7. End Sub
    Open Page
    Here is how to load a webpage into the webbrowser.
    VB Code:
    1. Private Sub Command2_Click()
    2.     WebBrowser1.ExecWB OLECMDID_OPEN, OLECMDEXECOPT_PROMPTUSER
    3. End Sub
    This is how to open a page, using the comman dialog's way
    VB Code:
    1. Option Explicit
    2. Private Sub Command1_Click()
    3. On Error Resume Next
    4.     With CommonDialog1
    5.         .DialogTitle = "Open File"
    6.         .Filter = "Web page (*.htm;*.html) | *.htm;*.html|" & _
    7.         "All Supported Picture formats|*.gif;*.tif;*.pcd;*.jpg;*.wmf;" & _
    8.         "*.tga;*.jpeg;*.ras;*.png;*.eps;*.bmp;*.pcx|" & _
    9.         "Text formats (*.txt;*.doc)|*.txt;*.doc|" & _
    10.         "All files (*.*)|*.*|"
    11.         .ShowOpen
    12.         .Flags = 5
    13.     WebBrowser1.Navigate2 .FileName
    14.     End With
    15. End Sub
    16. Private Sub Form_Load()
    17.     WebBrowser1.Navigate2 "www.google.com"
    18. End Sub
    Auto Submit
    This Simple Code I Made To show you how to make a submittion form. This code will autofill the need filled and submit it.
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strwebsite As String
    3.     Dim stremail As String
    4.         strwebsite = "http://www.mysite.com"
    5.             stremail = "myemail@host.com"
    6. WebBrowser1.Document.addurl.URL.Value = strwebsite
    7.     WebBrowser1.Document.addurl.Email.Value = stremail
    8.         WebBrowser1.Document.addurl.Submit
    9. End Sub
    10. Private Sub Form_Load()
    11.     WebBrowser1.Navigate "http://www.scrubtheweb.com/addurl.html"
    12. End Sub
    Using A ProgressBar With The Webbrowser
    This is to show how to use a progressbar with a webbrowser control.
    VB Code:
    1. Private Sub Form_Load()
    2.     WebBrowser1.Navigate "www.msn.com"
    3.     ProgressBar1.Appearance = ccFlat
    4.     ProgressBar1.Scrolling = ccScrollingSmooth
    5. End Sub
    6.  
    7. Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
    8. On Error Resume Next
    9.     If Progress = -1 Then ProgressBar1.Value = 100
    10.         Me.Caption = "100%"
    11.     If Progress > 0 And ProgressMax > 0 Then
    12.         ProgressBar1.Value = Progress * 100 / ProgressMax
    13.         Me.Caption = Int(Progress * 100 / ProgressMax) & "%"
    14.     End If
    15.     Exit Sub
    16. End Sub
    Setting a Control in a Webbrowser to focus
    This shows how to set a control inside the webbrowser into focus.
    VB Code:
    1. Private Sub Command1_Click()
    2.     WebBrowser1.Document.All("q").focus 'Set the search text filed in focus
    3. End Sub
    4.  
    5. Private Sub Command2_Click()
    6.     WebBrowser1.Document.All("btnI").focus 'Set the google "I Am feeling lucky in focus button"
    7. End Sub
    8.  
    9. Private Sub Form_Load()
    10.     WebBrowser1.Navigate "http://www.google.com/"
    11. End Sub

    Or you can use:
    VB Code:
    1. WebBrowser1.Document.getElementById("Object's Name").Focus
    Checkbox in a page, how to control it
    This is an example on how to check or uncheck the remember me checkbox on the google login page:

    VB Code:
    1. Private Sub Form_Load()
    2. WebBrowser1.Navigate "https://www.google.com/accounts/ManageAccount"
    3. End Sub
    4. Private Sub Check1_Click()
    5.     If Check1.Value = 0 Then
    6.         WebBrowser1.Document.All.PersistentCookie.Checked = False 'unchecked
    7.     Else
    8.         WebBrowser1.Document.All.PersistentCookie.Checked = True 'checked
    9.     End If
    10. End Sub
    Or

    VB Code:
    1. Private Sub Form_Load()
    2. WebBrowser1.Navigate "https://www.google.com/accounts/ManageAccount"
    3. End Sub
    4. Private Sub Check1_Click()
    5.     If Check1.Value = 0 Then
    6.         WebBrowser1.Document.All.PersistentCookie.Checked = 0 'unchecked
    7.     Else
    8.         WebBrowser1.Document.All.PersistentCookie.Checked = 1 'checked
    9.     End If
    10. End Sub
    Or
    VB Code:
    1. Private Sub Form_Load()
    2. WebBrowser1.Navigate "https://www.google.com/accounts/ManageAccount"
    3. End Sub
    4. Private Sub Check1_Click()
    5.     If Check1.Value = 0 Then
    6.         WebBrowser1.Document.getElementById("PersistentCookie").Checked = False 'unchecked
    7.     Else
    8.         WebBrowser1.Document.getElementById("PersistentCookie").Checked = True 'checked
    9.     End If
    10. End Sub
    Custom Right Click Menu
    This is an example show how to make your own custom right click menu. in order for this to work you must add the "Must Add Microsoft HTML Object Library" to your refrance.Also make your own custom menu using the menu editor I named my "mnu"
    Please Note it will effect all the context menus in the webbrowser.

    VB Code:
    1. 'Must Add Microsoft HTML Object Library
    2. Option Explicit
    3.     Public WithEvents HTML As HTMLDocument
    4.  
    5. Private Function HTML_oncontextmenu() As Boolean
    6.    HTML_oncontextmenu = False
    7.    PopupMenu mnu '<---Check the mnu to your own menu name
    8. End Function
    9.  
    10. Private Sub Form_Load()
    11.     WebBrowser1.Navigate "www.google.com"
    12. End Sub
    13.  
    14. Private Sub Form_Unload(Cancel As Integer)
    15.    Set HTML = Nothing
    16. End Sub
    17. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, _
    18.                                                  URL As Variant)
    19.    Set HTML = WebBrowser1.Document
    20. End Sub
    Last edited by wiz126; Mar 23rd, 2006 at 04:34 PM.
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  3. #3
    Lively Member
    Join Date
    Jun 2008
    Posts
    91

    Question Re: Webbrowser Control Tip and Examples

    Custom Right Click Menu
    This is an example show how to make your own custom right click menu. in order for this to work you must add the "Must Add Microsoft HTML Object Library" to your refrance.Also make your own custom menu using the menu editor I named my "mnu"
    Please Note it will effect all the context menus in the webbrowser.

    VB Code:
    1. 'Must Add Microsoft HTML Object Library
    2. Option Explicit
    3.     Public WithEvents HTML As HTMLDocument
    4.  
    5. Private Function HTML_oncontextmenu() As Boolean
    6.    HTML_oncontextmenu = False
    7.    PopupMenu mnu '<---Check the mnu to your own menu name
    8. End Function
    9.  
    10. Private Sub Form_Load()
    11.     WebBrowser1.Navigate "www.google.com"
    12. End Sub
    13.  
    14. Private Sub Form_Unload(Cancel As Integer)
    15.    Set HTML = Nothing
    16. End Sub
    17. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, _
    18.                                                  URL As Variant)
    19.    Set HTML = WebBrowser1.Document
    20. End Sub
    Might be bringing an old post back alive but I definately needed help with this. The above code got me started on making my own context menu for the webbrowser control. However, My webbrowser control page that it navigates to has an iframe. When I right click on the iframe it does not keep the contextmenu, is there a way to fix this?

    Thanks,
    n3m.

  4. #4
    Junior Member
    Join Date
    Nov 2012
    Posts
    22

    Re: Webbrowser Control Tip and Examples

    Checkbox in a page, how to control it

    in the website, the checkbox i wanna check, the code is like this
    <input type="checkbox" onchange="groupCheck(this.checked)">

    and from your guide, WebBrowser1.Document.GetElementById("PersistentCookie").Checked = True 'checked
    that i cant find, help me out with this, i'm using visual studio 2008

  5. #5
    Hyperactive Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    416

    Re: Webbrowser Control Tip and Examples

    The Custom Right Click Menu code also seems to work as an alternate way to disable the context menu without requiring subclassing or use of a helper DLL like your earlier solution outlines. Simply use the custom right click menu code you have but omit the line which shows a custom popup menu.

    Code:
    'Must Add Microsoft HTML Object Library
    Option Explicit
        Public WithEvents HTML As HTMLDocument
     
    Private Function HTML_oncontextmenu() As Boolean
       HTML_oncontextmenu = False
    End Function
     
    Private Sub Form_Load()
        WebBrowser1.Navigate "www.google.com"
    End Sub
     
    Private Sub Form_Unload(Cancel As Integer)
       Set HTML = Nothing
    End Sub
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, _
                                                     URL As Variant)
       Set HTML = WebBrowser1.Document
    End Sub

  6. #6

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Webbrowser Control Tip and Examples

    ~~~~~~~...:::Toturial Updates:::...~~~~~~~
    01-27-2006 06:25 PM - Main Toturial
    01-27-2006 06:33 PM- Save/Open Page , Grab Links On Page
    02-07-2006 06:14 PM - Auto Submitting
    02-14-2006 03:16 PM - Using A ProgressBar With The Webbrowser
    03-22-2006 06:03 PM - Checkbox in a page
    Last edited by wiz126; Mar 22nd, 2006 at 06:03 PM.
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  7. #7
    New Member
    Join Date
    Jan 2011
    Posts
    13

    Re: Webbrowser Control Tip and Examples

    and how can i get text from webbrowser to my form in vb6

  8. #8
    New Member
    Join Date
    Dec 2010
    Posts
    12

    Re: Webbrowser Control Tip and Examples

    After a very long time of spending working with the webbrowser control I have learned quite a bit as far as how to make it work. Now I think I have hit another stump. I am trying to read a table with no id on a page. The page only has one table on it but I cannot seem to get the code to pickup on it. Any suggestions?

    Here is what I have so far:
    Code:
    AtmsQualsLength = WebBrowser1.Document.getElementsByTagName("table").rows.length
    And I have also tried:
    Code:
    AtmsCoursesLength = WebBrowser1.Document.getelementbyid("table").rows.length - 1
    The reason why I am putting table as the table name is because of this post
    http://www.eggheadcafe.com/software/...lass-name.aspx

    Thanks to all

  9. #9
    New Member
    Join Date
    Dec 2010
    Posts
    12

    Re: Webbrowser Control Tip and Examples

    Well I was not able to ever find a good solution for reading a table with no ID instead I used the instr function and with some calculations read the data from its source code. Its a pain and if the format changes then I would have to update the code but here is what I have.

    Code:
    '// Locate and assign Pay Shop
        lngSupCode = InStr(WebBrowser1.Document.documentelement.innerhtml, "Pay Shop")
        lngSupCode = lngSupCode + 210
        strBuildData = Mid(WebBrowser1.Document.documentelement.innerhtml, lngSupCode)
        lngSupCode = InStr(strBuildData, "&nbsp;")
        strBuildData = Left(strBuildData, lngSupCode)
        strBuildData = Mid(strBuildData, 18)
        lngSupCode = InStr(strBuildData, "&") - 1
        strBuildData = Left(strBuildData, lngSupCode)
        strPayShop = strBuildData
        
        '// Locate and assign Assn'd Shop
        lngSupCode = InStr(WebBrowser1.Document.documentelement.innerhtml, "Assn'd Shop")
        lngSupCode = lngSupCode + 210
        strBuildData = Mid(WebBrowser1.Document.documentelement.innerhtml, lngSupCode)
        lngSupCode = InStr(strBuildData, "&nbsp;")
        strBuildData = Left(strBuildData, lngSupCode)
        strBuildData = Mid(strBuildData, 14)
        lngSupCode = InStr(strBuildData, "&") - 1
        strBuildData = Left(strBuildData, lngSupCode)
        strAssignedShop = strBuildData
        
        '// Locate and assign Supv.
        lngSupCode = InStr(WebBrowser1.Document.documentelement.innerhtml, "Supv.")
        lngSupCode = lngSupCode + 200
        strBuildData = Mid(WebBrowser1.Document.documentelement.innerhtml, lngSupCode)
        lngSupCode = InStr(strBuildData, "&nbsp;")
        strBuildData = Left(strBuildData, lngSupCode)
        strBuildData = Mid(strBuildData, 16)
        lngSupCode = InStr(strBuildData, "&") - 1
        strBuildData = Left(strBuildData, lngSupCode)
        strSupCode = strBuildData
        
        '// Locate and assign Shift
        lngSupCode = InStr(WebBrowser1.Document.documentelement.innerhtml, "Shift")
        lngSupCode = lngSupCode + 200
        strBuildData = Mid(WebBrowser1.Document.documentelement.innerhtml, lngSupCode)
        lngSupCode = InStr(strBuildData, "&nbsp;")
        strBuildData = Left(strBuildData, lngSupCode)
        strBuildData = Mid(strBuildData, 14)
        lngSupCode = InStr(strBuildData, "&") - 1
        strBuildData = Left(strBuildData, lngSupCode)
        strShift = strBuildData
    I just wanted to share what I have done so hopefully its usefull to someone.

    Thanks,

    TheChazm

  10. #10
    Member
    Join Date
    Mar 2006
    Location
    Palakkad,Kerala,India.
    Posts
    52

    Re: Webbrowser Control Tip and Examples

    I didnt Knew that one can disable Right Click on that. i guess that works. Well can you say how to enable AJAX on one. and how to add a menu on existing rightclick.

  11. #11
    New Member
    Join Date
    Mar 2006
    Posts
    13

    Re: Webbrowser Control Tip and Examples

    how can i add center click???

  12. #12

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Webbrowser Control Tip and Examples

    Quote Originally Posted by oasa
    I didnt Knew that one can disable Right Click on that. i guess that works. Well can you say how to enable AJAX on one. and how to add a menu on existing rightclick.
    Looks like I indeed forgat to show how, well I just added "Custom Right Click Menu" and i showed how to have your how popup right click menu

    Quote Originally Posted by Pacca
    how can i add center click???
    Are you talking about the middle (wheel) button? if yes then, I don't think you can, You might globaly (in the whole app). I will try playing with some code see if i can get it to work.
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  13. #13
    New Member
    Join Date
    Mar 2006
    Posts
    13

    Re: Webbrowser Control Tip and Examples

    Quote Originally Posted by wiz126
    Are you talking about the middle (wheel) button? if yes then, I don't think you can, You might globaly (in the whole app). I will try playing with some code see if i can get it to work.
    yes about this

  14. #14
    New Member
    Join Date
    Mar 2006
    Posts
    13

    Re: Webbrowser Control Tip and Examples

    nobody can help me???

  15. #15

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Webbrowser Control Tip and Examples

    Try making the webbrowser control in a custom control and see if you can catch the middle button. Otherwise I guess its not possible in visual basic 6 (atleast)
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  16. #16
    New Member
    Join Date
    Apr 2006
    Posts
    2

    Re: Webbrowser Control Tip and Examples

    Hi,
    I've been trying the example to change the font size and I typed in the vb 6 code and I have the internet control added.

    With WebBrowser1
    .Navigate strAddress
    .ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(4), vbNull
    End With

    I keep getting
    Method 'ExecWB' of object 'IWebBrowser2' failed. as the error message
    I even tried CLng(1)

    Thanks for the help
    Brian

  17. #17
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Webbrowser Control Tip and Examples


  18. #18
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Webbrowser Control Tip and Examples

    Good tips for beginners
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  19. #19
    New Member
    Join Date
    Mar 2006
    Posts
    13

    Re: Webbrowser Control Tip and Examples

    a littler problem...
    i disabled the right click menu and i made my own...now i need a code for a button in the menu that when i click on a link it comes the menu "open in a new page"...can any1 help me?
    Last edited by Pacca; Apr 23rd, 2006 at 02:12 PM.

  20. #20
    New Member
    Join Date
    Mar 2006
    Posts
    13

    Re: Webbrowser Control Tip and Examples

    no solutions?

  21. #21
    New Member
    Join Date
    Jun 2006
    Posts
    1

    Re: Webbrowser Control Tip and Examples

    Hi all,

    I know how to auto submit form using form name. now i want submit form using form id. How to do that?

  22. #22
    New Member
    Join Date
    Jul 2006
    Posts
    13

    Re: Webbrowser Control Tip and Examples

    How about autoscroll function? Could you introduce more?

  23. #23

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Webbrowser Control Tip and Examples

    Quote Originally Posted by dankasolutions
    How about autoscroll function? Could you introduce more?
    Can you explain more on what you are looking for?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  24. #24
    New Member
    Join Date
    Jul 2006
    Posts
    13

    Re: Webbrowser Control Tip and Examples

    I mean that could you introduce how to make a web browser control can autoscroll its content.

  25. #25
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Webbrowser Control Tip and Examples

    Nice code. Two questions tho. One, does the link getting function also get image links? or just text links. And secondly is there a way to get all the srcs of a webpage, i.e. images, css files, etc.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  26. #26
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Webbrowser Control Tip and Examples

    Get page source:
    VB Code:
    1. Dim pageSource As String
    2. pageSource = webBrowser.document.body.parentElement.innerHTML

    Get images:
    VB Code:
    1. Dim pageImages As Object
    2. pageImages = webBrowser.document.getElementsByTagName("img")

    Get links:
    VB Code:
    1. Dim pageLinks As Object
    2. pageLinks = webBrowser.document.getElementsByTagName("a")

    Get image links:
    VB Code:
    1. Dim pageImageLinks As Collection
    2. Dim pageLinks As Object
    3. pageLinks = webBrowser.document.getElementsByTagName("a")
    4.  
    5. Dim link As Object
    6. Dim linkChildren As Object
    7. For Each link In pageLinks
    8.   linkChildren = link.getElementsByTagName("img")
    9.   ' Can't remember if this next bit will work, might need fiddling
    10.   If (linkChildren.Count) _
    11.     pageImageLinks.Add(link)
    12. Next

    Bear in mind it's a while since I've used VB, most of that is converted from JS.

  27. #27
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Webbrowser Control Tip and Examples

    I found the solution:

    VB Code:
    1. Dim HTMLdoc As HTMLDocument
    2. Dim pageImages As HTMLImg
    3.                
    4.    HTMLDoc = Webbrowser1.Document
    5.              
    6.      For Each pageImages In HTMLdoc.images
    7.                    
    8.                    List2.AddItem pageImages.src
    9.  
    10.      Next pageImages
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  28. #28
    Member
    Join Date
    Jul 2006
    Posts
    34

    Re: Webbrowser Control Tip and Examples

    Is there any way to fill an input box type = "file" with a filename to upload automatically in the webbrowser? I can't seem to get this to work. I can fill in everything else and click submit, but I can not get the filename to show up in the input box. Any suggestions?

    jam

  29. #29
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    Re: Webbrowser Control Tip and Examples

    Alright,i have a question.when i connect to a website,the server identifies the make and version of my browser.Now is it possible to change the header info? for eg i want my app to be identified as a mozilla browser and not a ie one.I think it is possible with the ".ExecWb" method .Can someone give me an example ?

  30. #30
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Webbrowser Control Tip and Examples

    I do not think that you can change the headers using the webbrowser. I think you can do it using the inet control execute method. Then you could write the recieved code to the browser.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  31. #31
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Webbrowser Control Tip and Examples

    Hey,

    How could i get the src's of all the objects on the page. e.g. flash player, movie, etc.

    Thanks
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  32. #32
    Addicted Member
    Join Date
    Aug 2006
    Posts
    211

    Re: Webbrowser Control Tip and Examples

    Hmm.. I'm having trouble with radio buttons on webforms. What is the value to set for "selected" ? I tried getting the value and it gives me a EMPTY for the variable set for that value even when it's checked. shipFromZipCode is the name of the radio button.

    x = WebBrowser1.Document.Forms(0).shipFromZipCode.Value
    Last edited by DssTrainer; Aug 15th, 2006 at 09:13 AM.

  33. #33
    Addicted Member
    Join Date
    Aug 2006
    Posts
    211

    Re: Webbrowser Control Tip and Examples

    I figured it out.. For radio buttons, since they are typically linked to the disabling of other buttons, they all share the same name but different ID. so instead of the name, you need to use the ID. You can also use value or checked depending on what property format you want.

  34. #34
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Webbrowser Control Tip and Examples

    After reding through this tutorial, I was faced by a challenge. Am making my page using "Making page on startup" tips where I create a HTML string. Now, I want to display values from a database, how do I call these values into the HTML? I have my recordset ready and what is remaining is calling the values onto the page. I will appreciate your help.

    Thanks.

  35. #35
    Junior Member
    Join Date
    Oct 2006
    Posts
    22

    Re: Webbrowser Control Tip and Examples

    This thread makes me registering. Excellent! Thank you.
    I am developing a software that uses web control, but having a small problem:
    When I want to have number of controls in form, it would be document.forms(i).length, right?
    But if form has control with name "length", it returns reference to this control and I can't have what a I'm looking for.
    Can anyone help me with that?
    Thank you very much.
    Tuan.

  36. #36
    New Member
    Join Date
    Jul 2005
    Posts
    2

    Question IE6 style controls in Web Browser control

    Is there any way to view pages in the Web Browser control with the page controls (buttons, check boxes, etc.) adopting the XP style as IE6 already does. I know there is a way using a resouce file to get most of the Windows Common Controls to adopt the XP them. Is there a similar way to get the Web Browser control to do this?

  37. #37
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Webbrowser Control Tip and Examples

    It sure would be nice if VB6 had intelisence(?) to go with the browser control.
    I just found wbrBrowser.Document.Title and I know it has wbrBrowser.Document.documentElement.

    Does anyone know where to get a list of the full model?
    Or at least a good part of it?

    Right now I'm trying to find out how to pull the Meta Tags, but haven't got a clue where to find them.

    I could write a string parser to get them, but it'd be nice just to use the control itself.

  38. #38
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Webbrowser Control Tip and Examples

    You need to reference the Microsoft HTML Object Library and cast wbrBrowser.Document into a HTMLDocument type.

    VB Code:
    1. Dim doc As HTMLDocument
    2. Set doc = wbrBrowser.Document

  39. #39
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Webbrowser Control Tip and Examples

    Thanks Penagate.
    That should be a big help!

    I'm still lost in there without a help file, but at least that gives some road signs.

    I'm trying to find the Meta tags and FavIcon, if they have one.

    Code:
    <link rel="shortcut icon" href="/favicon.ico" />
    <meta name="description" content="Visual Basic Discussions plus .NET, C#, game programming, and more (http://www.VBForums.com)" />

  40. #40
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Webbrowser Control Tip and Examples

    Check the type names
    VB Code:
    1. Dim favicon As String
    2. Dim description As String
    3.  
    4. Dim links As HTMLElementCollection
    5. Dim metas As HTMLElementCollection
    6.  
    7. Set links = wbrBrowser.Document.GetElementsByTagName("link")
    8. Set metas = wbrBrowser.Document.GetElementsByTagName("meta")
    9.  
    10. Dim link As HTMLLinkElement
    11. For Each link In links
    12.   If (InStr(link.GetAttribute("rel"), "icon") Then
    13.     favicon = link.GetAttribute("href")
    14.     Exit For
    15.   End If
    16. Next
    17.  
    18. Dim meta As HTMLMetaElement
    19. For Each meta In metas
    20.   If (meta.HasAttribute("description")) Then
    21.     description = meta.GetAttribute("content")
    22.     Exit For
    23.   End If
    24. Next

    Hope that helps.

    For documentation see DOM - MDC.

Page 1 of 4 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width