Webbrowser Control Tips
Webbrowser Control Tips
Table of Contents
Introduction .............................................................................................................................................. 2 Navigating to a site ................................................................................................................................... 3 Opening a popup window with your app ................................................................................................. 3 Check if word/string is found on the page................................................................................................ 3 Regular Browser Functions ....................................................................................................................... 4 Advanced Browser Functions.................................................................................................................... 4 Changing web browser Font Size .............................................................................................................. 5 Making page on startup ............................................................................................................................ 6 Disabling functions appropriately (Back/Forward) ................................................................................... 6 Disabling functions appropriately (page setup/print preview/print setup) ............................................. 7 Removing Right Click Menu From the browser control ............................................................................ 8 Custom Right Click Menu .......................................................................................................................... 8 Grab all links on the page.......................................................................................................................... 9 Save Page .................................................................................................................................................. 9 Open Page ............................................................................................................................................... 10 Auto Submit ............................................................................................................................................ 10 Using A ProgressBar With The Webbrowser .......................................................................................... 11 Setting a Control in a Webbrowser to focus ........................................................................................... 11 Checkbox in a page, how to control it .................................................................................................... 12
Introduction
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 browsers 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
WebBrowser1.Navigate "www.google.com"
Save Page
This code shows you how to save the browser's page.
Option Explicit Private Sub Command1_Click() WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT End Sub Private Sub Form_Load() WebBrowser1.Navigate2 "www.google.com" End Sub
Open Page
Here is how to load a webpage into the webbrowser.
Private Sub Command2_Click() WebBrowser1.ExecWB OLECMDID_OPEN, OLECMDEXECOPT_PROMPTUSER End Sub
Auto Submit
This code will autofill the need filled and submit it.
Private Sub Command1_Click() Dim strwebsite As String Dim stremail As String strwebsite = "http://www.mysite.com" stremail = "[email protected]" WebBrowser1.Document.addurl.URL.Value = strwebsite WebBrowser1.Document.addurl.Email.Value = stremail WebBrowser1.Document.addurl.Submit End Sub Private Sub Form_Load() WebBrowser1.Navigate "http://www.scrubtheweb.com/addurl.html" End Sub
Or
Private Sub Form_Load() WebBrowser1.Navigate "https://www.google.com/accounts/ManageAccount" End Sub Private Sub Check1_Click() If Check1.Value = 0 Then WebBrowser1.Document.All.PersistentCookie.Checked = 0 'unchecked Else WebBrowser1.Document.All.PersistentCookie.Checked = 1 'checked End If End Sub
Or
Private Sub Form_Load() WebBrowser1.Navigate "https://www.google.com/accounts/ManageAccount" End Sub Private Sub Check1_Click() If Check1.Value = 0 Then WebBrowser1.Document.getElementById("PersistentCookie").Checked = False 'unchecked Else WebBrowser1.Document.getElementById("PersistentCookie").Checked = True 'checked End If End Sub