-
Jan 27th, 2006, 06:25 PM
#1
Thread Starter
Frenzied Member
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:
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:
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Dim frm As Form1
Set frm = New Form1
Set ppDisp = frm.WebBrowser1.Object
frm.Show
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:
Private Sub Command1_Click()
Dim strfindword As String
strfindword = InputBox("What are you looking for?", "Find", "") ' what word to find?
If WebPageContains(strfindword) = True Then 'check if the word is in page
MsgBox "The webpage contains the text" 'string is in page
Else
MsgBox "The webpage doesn't contains the text" 'string is not in page
End If
End Sub
Private Function WebPageContains(ByVal s As String) As Boolean
Dim i As Long, EHTML
For i = 1 To WebBrowser1.Document.All.length
Set EHTML = _
WebBrowser1.Document.All.Item(i)
If Not (EHTML Is Nothing) Then
If InStr(1, EHTML.innerHTML, _
s, vbTextCompare) > 0 Then
WebPageContains = True
Exit Function
End If
End If
Next i
End Function
Private Sub Form_Load()
WebBrowser1.Navigate2 "www.msn.com"
End Sub
Making page on startup
This code show you how to make a page and show it on event.
VB Code:
Private Sub Form_Load()
WebBrowser1.Navigate "about:blank"
End Sub
Private Sub Command1_Click()
Dim HTML As String
'----------The HTML CODE GOES FROM HERE AND DOWN----------
HTML = "<HTML>" & _
"<TITLE>Page On Load</TITLE>" & _
"<BODY>" & _
"<FONT COLOR = BLUE>" & _
"This is a " & _
"<FONT SIZE = 5>" & _
"<B>" & _
"programmatically " & _
"</B>" & _
"</FONT SIZE>" & _
"made page" & _
"</FONT>" & _
"</BODY>" & _
"</HTML>"
'----------The HTML CODE GOES HERE AND ABOVE----------
WebBrowser1.Document.Write HTML
End Sub
Regular Browser Functions
This are the basic internet browser's functions.
VB Code:
Private Sub Command1_Click(Index As Integer)
On Error Resume Next ' just in case there is no page back or forward
'I showed how to disabel them if you scroll down more
Select Case Index
Case 0 'Go Back Button
WebBrowser1.GoBack 'Go Back one Page
Case 1 'Go Forward Button
WebBrowser1.GoForward 'Go Forward one Page
Case 2 'Stop Button
WebBrowser1.Stop 'stop page
Case 3 'Refresh Button
WebBrowser1.Refresh 'refresh page
Case 4 'Go Home Button
WebBrowser1.GoHome 'Go to home page
Case 5 'Search Button
WebBrowser1.GoSearch 'Search
End Select
End Sub
Advanced Browser Functions
This are the more complex browser functions like print and page Properties.
VB Code:
Private Sub Command1_Click() 'Print Button
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT 'Show Print Window
End Sub
Private Sub Command2_Click() 'Print Preview Button
WebBrowser1.ExecWB OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DODEFAULT 'Show Print Preview Window
End Sub
Private Sub Command3_Click() 'Page Setup Button
WebBrowser1.ExecWB OLECMDID_PAGESETUP, OLECMDEXECOPT_DODEFAULT 'Show Page Setup Window
End Sub
Private Sub Command4_Click() 'Page Properties Button
WebBrowser1.ExecWB OLECMDID_PROPERTIES, OLECMDEXECOPT_DODEFAULT 'Show Page Properties Window
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "www.google.com"
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:
Private Sub Command1_Click() ' Smallest Button
On Error Resume Next
WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(0), vbNull
End Sub
Private Sub Command2_Click() 'Small Button
On Error Resume Next
WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(1), vbNull
End Sub
Private Sub Command3_Click() 'Medium Button
On Error Resume Next
WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(2), vbNull
End Sub
Private Sub Command4_Click() 'Large Button
On Error Resume Next
WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(3), vbNull
End Sub
Private Sub Command5_Click() 'Largest Button
On Error Resume Next
WebBrowser1.ExecWB OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(4), vbNull
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate2 "www.google.com"
End Sub
Disabling functions appropriately (Back/Forward)
This code shows you how to appropriately disable the back and forward button.
VB Code:
Private Sub Command1_Click() 'Go Back Button
WebBrowser1.GoBack 'Go Back
End Sub
Private Sub Command2_Click() 'Go Forward Button
WebBrowser1.GoForward 'Go Forward
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "www.google.com"
End Sub
Private Sub WebBrowser1_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)
Select Case Command
Case 1 'Forward
Command2.Enabled = Enable
Case 2 'Back
Command1.Enabled = Enable
End Select
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:
Private Sub Command1_Click() 'Print Button
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT 'Show Print Window
End Sub
Private Sub Command2_Click() 'Print Preview Button
WebBrowser1.ExecWB OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DODEFAULT 'Show Print Preview Window
End Sub
Private Sub Command3_Click() 'Page Setup Button
WebBrowser1.ExecWB OLECMDID_PAGESETUP, OLECMDEXECOPT_DODEFAULT 'Show Page Setup Window
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "www.google.com"
End Sub
Public Function Enable_or_Disable()
If WebBrowser1.QueryStatusWB(OLECMDID_PRINT) = 0 Then
Command1.Enabled = False
Else
Command1.Enabled = True
End If
If WebBrowser1.QueryStatusWB(OLECMDID_PRINTPREVIEW) = 0 Then
Command2.Enabled = False
Else
Command2.Enabled = True
End If
If WebBrowser1.QueryStatusWB(OLECMDID_PAGESETUP) = 0 Then
Command3.Enabled = False
Else
Command3.Enabled = True
End If
End Function
Private Sub WebBrowser1_BeforeNavigate2 _
(ByVal pDisp As Object, _
URL As Variant, _
Flags As Variant, _
TargetFrameName As Variant, _
PostData As Variant, _
Headers As Variant, _
Cancel As Boolean)
Enable_or_Disable
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Enable_or_Disable
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:
Option Explicit
Dim CustomWB As WBCustomizer 'Deceler the CustomWB
Private Sub Form_Load()
Set CustomWB = New WBCustomizer
With CustomWB
.EnableContextMenus = False 'Disable The Menu
.EnableAllAccelerators = True
Set .WebBrowser = WebBrowser1
End With
WebBrowser1.Navigate "www.google.com"
CustomWB.EnableContextMenus = False
End Sub
Last edited by wiz126; Mar 23rd, 2006 at 03:46 PM.
-
Jan 27th, 2006, 06:33 PM
#2
Thread Starter
Frenzied Member
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:
Option Explicit
Private Sub Form_Load()
WebBrowser1.Navigate "www.vbforums.com"
End Sub
Private Sub WebBrowser1_DownloadComplete()
'you must add the "Microsoft HTML Object Library"!!!!!!!!!
Dim HTMLdoc As HTMLDocument
Dim HTMLlinks As HTMLAnchorElement
Dim STRtxt As String
' List the links.
On Error Resume Next
Set HTMLdoc = WebBrowser1.Document
For Each HTMLlinks In HTMLdoc.links
STRtxt = STRtxt & HTMLlinks.href & vbCrLf
Next HTMLlinks
Text1.Text = STRtxt
End Sub
You can add this code in order to log this files.
VB Code:
Open "C:\Documents and Settings\[YOU USERNAME]\Desktop\link log.txt" For Append As #1
Print #1, STRtxt
Close #1
Save Page
This code shows you how to save the browser's page.
VB Code:
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.
VB Code:
Private Sub Command2_Click()
WebBrowser1.ExecWB OLECMDID_OPEN, OLECMDEXECOPT_PROMPTUSER
End Sub
This is how to open a page, using the comman dialog's way
VB Code:
Option Explicit
Private Sub Command1_Click()
On Error Resume Next
With CommonDialog1
.DialogTitle = "Open File"
.Filter = "Web page (*.htm;*.html) | *.htm;*.html|" & _
"All Supported Picture formats|*.gif;*.tif;*.pcd;*.jpg;*.wmf;" & _
"*.tga;*.jpeg;*.ras;*.png;*.eps;*.bmp;*.pcx|" & _
"Text formats (*.txt;*.doc)|*.txt;*.doc|" & _
"All files (*.*)|*.*|"
.ShowOpen
.Flags = 5
WebBrowser1.Navigate2 .FileName
End With
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate2 "www.google.com"
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:
Private Sub Command1_Click()
Dim strwebsite As String
Dim stremail As String
strwebsite = "http://www.mysite.com"
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
Using A ProgressBar With The Webbrowser
This is to show how to use a progressbar with a webbrowser control.
VB Code:
Private Sub Form_Load()
WebBrowser1.Navigate "www.msn.com"
ProgressBar1.Appearance = ccFlat
ProgressBar1.Scrolling = ccScrollingSmooth
End Sub
Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
On Error Resume Next
If Progress = -1 Then ProgressBar1.Value = 100
Me.Caption = "100%"
If Progress > 0 And ProgressMax > 0 Then
ProgressBar1.Value = Progress * 100 / ProgressMax
Me.Caption = Int(Progress * 100 / ProgressMax) & "%"
End If
Exit Sub
End Sub
Setting a Control in a Webbrowser to focus
This shows how to set a control inside the webbrowser into focus.
VB Code:
Private Sub Command1_Click()
WebBrowser1.Document.All("q").focus 'Set the search text filed in focus
End Sub
Private Sub Command2_Click()
WebBrowser1.Document.All("btnI").focus 'Set the google "I Am feeling lucky in focus button"
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "http://www.google.com/"
End Sub
Or you can use:
VB Code:
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:
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 = False 'unchecked
Else
WebBrowser1.Document.All.PersistentCookie.Checked = True 'checked
End If
End Sub
Or
VB Code:
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
VB Code:
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
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:
'Must Add Microsoft HTML Object Library
Option Explicit
Public WithEvents HTML As HTMLDocument
Private Function HTML_oncontextmenu() As Boolean
HTML_oncontextmenu = False
PopupMenu mnu '<---Check the mnu to your own menu name
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
Last edited by wiz126; Mar 23rd, 2006 at 04:34 PM.
-
Feb 7th, 2006, 06:12 PM
#3
Thread Starter
Frenzied Member
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.
-
Mar 14th, 2006, 01:48 AM
#4
Member
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.
-
Mar 23rd, 2006, 10:23 AM
#5
New Member
Re: Webbrowser Control Tip and Examples
how can i add center click???
-
Mar 23rd, 2006, 04:32 PM
#6
Thread Starter
Frenzied Member
Re: Webbrowser Control Tip and Examples
 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
 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.
-
Mar 24th, 2006, 01:24 AM
#7
New Member
Re: Webbrowser Control Tip and Examples
 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
-
Mar 31st, 2006, 10:23 AM
#8
New Member
Re: Webbrowser Control Tip and Examples
-
Mar 31st, 2006, 06:25 PM
#9
Thread Starter
Frenzied Member
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)
-
Apr 18th, 2006, 11:09 PM
#10
New Member
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
-
Apr 18th, 2006, 11:18 PM
#11
Re: Webbrowser Control Tip and Examples
-
Apr 19th, 2006, 02:38 AM
#12
Fanatic Member
Re: Webbrowser Control Tip and Examples
Good tips for beginners
-
Apr 20th, 2006, 12:32 PM
#13
New Member
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.
-
Apr 23rd, 2006, 02:00 AM
#14
New Member
Re: Webbrowser Control Tip and Examples
-
Jun 4th, 2006, 04:12 AM
#15
New Member
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?
-
Jul 12th, 2006, 02:49 AM
#16
New Member
Re: Webbrowser Control Tip and Examples
How about autoscroll function? Could you introduce more?
-
Jul 12th, 2006, 11:43 AM
#17
Thread Starter
Frenzied Member
Re: Webbrowser Control Tip and Examples
 Originally Posted by dankasolutions
How about autoscroll function? Could you introduce more?
Can you explain more on what you are looking for?
-
Jul 12th, 2006, 07:52 PM
#18
New Member
Re: Webbrowser Control Tip and Examples
I mean that could you introduce how to make a web browser control can autoscroll its content.
-
Jul 14th, 2006, 04:30 AM
#19
Hyperactive Member
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
-
Jul 14th, 2006, 11:16 PM
#20
Re: Webbrowser Control Tip and Examples
Get page source:
VB Code:
Dim pageSource As String
pageSource = webBrowser.document.body.parentElement.innerHTML
Get images:
VB Code:
Dim pageImages As Object
pageImages = webBrowser.document.getElementsByTagName("img")
Get links:
VB Code:
Dim pageLinks As Object
pageLinks = webBrowser.document.getElementsByTagName("a")
Get image links:
VB Code:
Dim pageImageLinks As Collection
Dim pageLinks As Object
pageLinks = webBrowser.document.getElementsByTagName("a")
Dim link As Object
Dim linkChildren As Object
For Each link In pageLinks
linkChildren = link.getElementsByTagName("img")
' Can't remember if this next bit will work, might need fiddling
If (linkChildren.Count) _
pageImageLinks.Add(link)
Next
Bear in mind it's a while since I've used VB, most of that is converted from JS.
-
Jul 15th, 2006, 09:11 AM
#21
Hyperactive Member
Re: Webbrowser Control Tip and Examples
I found the solution:
VB Code:
Dim HTMLdoc As HTMLDocument
Dim pageImages As HTMLImg
HTMLDoc = Webbrowser1.Document
For Each pageImages In HTMLdoc.images
List2.AddItem pageImages.src
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
-
Jul 21st, 2006, 02:25 PM
#22
Member
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
-
Jul 22nd, 2006, 01:30 PM
#23
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 ?
-
Jul 30th, 2006, 02:30 AM
#24
Hyperactive Member
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
-
Aug 15th, 2006, 03:51 AM
#25
Hyperactive Member
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
-
Aug 15th, 2006, 08:36 AM
#26
Addicted Member
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.
-
Aug 15th, 2006, 10:11 AM
#27
Addicted Member
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.
-
Aug 21st, 2006, 02:42 AM
#28
Hyperactive Member
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.
-
Oct 20th, 2006, 05:47 AM
#29
Junior Member
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.
-
Oct 26th, 2006, 06:11 PM
#30
New Member
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?
-
Dec 2nd, 2006, 05:52 PM
#31
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.
-
Dec 3rd, 2006, 12:14 AM
#32
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:
Dim doc As HTMLDocument
Set doc = wbrBrowser.Document
-
Dec 3rd, 2006, 10:01 AM
#33
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)" />
-
Dec 3rd, 2006, 10:05 AM
#34
Re: Webbrowser Control Tip and Examples
Check the type names
VB Code:
Dim favicon As String
Dim description As String
Dim links As HTMLElementCollection
Dim metas As HTMLElementCollection
Set links = wbrBrowser.Document.GetElementsByTagName("link")
Set metas = wbrBrowser.Document.GetElementsByTagName("meta")
Dim link As HTMLLinkElement
For Each link In links
If (InStr(link.GetAttribute("rel"), "icon") Then
favicon = link.GetAttribute("href")
Exit For
End If
Next
Dim meta As HTMLMetaElement
For Each meta In metas
If (meta.HasAttribute("description")) Then
description = meta.GetAttribute("content")
Exit For
End If
Next
Hope that helps.
For documentation see DOM - MDC.
-
Dec 3rd, 2006, 11:09 AM
#35
Re: Webbrowser Control Tip and Examples
I'm getting Type Mismatch errors on both of these.
VB Code:
Set links = wbrBrowser.Document.getElementsByTagName("link")
Set metas = wbrBrowser.Document.getElementsByTagName("meta")
I have added the reference to the Microsoft HTML Object Library .
-
Dec 3rd, 2006, 11:24 AM
#36
Re: Webbrowser Control Tip and Examples
odd, try MSHTML.HTMLElementCollection
Failing that, look in the Object Browser and see what getElementsByTagName returns.
-
Dec 3rd, 2006, 12:07 PM
#37
Re: Webbrowser Control Tip and Examples
Looks like I got it.
VB Code:
Dim myHTMLDoc As New HTMLDocument
Dim colA As IHTMLElementCollection
Dim myA As IHTMLElement
Set myHTMLDoc = wbrBrowser.Document
Set colA = myHTMLDoc.getElementsByTagName("link")
For Each myA In colA
If LCase(myA.getAttribute("rel")) = "shortcut icon" Then
Debug.Print myA.getAttribute("href")
Exit For
End If
Next
Set colA = myHTMLDoc.getElementsByTagName("meta")
For Each myA In colA
If LCase(myA.getAttribute("name")) = "description" Then
Debug.Print myA.getAttribute("content")
End If
Next
Set myA = Nothing
Set colA = Nothing
Set myHTMLDoc = Nothing
Thanks for your help Penagate!
-
Dec 3rd, 2006, 12:21 PM
#38
Re: Webbrowser Control Tip and Examples
BTW, do I need the LCase's I used or are the elements always returned as lower case?
-
Dec 3rd, 2006, 07:06 PM
#39
Re: Webbrowser Control Tip and Examples
 Originally Posted by longwolf
BTW, do I need the LCase's I used or are the elements always returned as lower case?
They're returned as specified in the source. So, LCases are a good idea.
-
Mar 17th, 2007, 07:43 AM
#40
New Member
how to Pick a text from Table in a page
Dear 1 Heartly appreciate your this briefly lesson on Webbrowser
here 1 m facing a problem.
I wanna pick some text from a table cell like in blow table I need to pick
1.(216)216-2167
2."NO"
3. "0%"
<TABLE WIDTH="100%" CELLSPACING="1" CELLPADDING="3" BORDER="0">
<TR CLASS="backgroundborderpeach" ALIGN="center">
<TD>10-Digit Phone Number</TD><TD>Approved</TD><TD>Rebate Percentage</TD></TR>
<TR ALIGN="center" CLASS="backwhite1">
<TD>(216)216-2167</TD><TD>No</TD><TD>0%</TD></TR>
</TABLE>
------------------------------------------------------------------------------------------------
and in this table I need to pock
1.Qualifies for 100% On Dec 1, 2008
where Number of % can be changed like 10% or 50%
<TABLE WIDTH="100%" CELLSPACING="1" CELLPADDING="3" BORDER="0">
<TR><TD> </TD></TR>
<TR CLASS="backwhite1"><TD><IMG SRC="/ec/images/leftarrow.gif" width="35px" BORDER="0"> <SPAN CLASS="HEAVY">Qualifies for 100% On Dec 1, 2008</SPAN></TD></TR></TABLE>
so PLZ guide me to do this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|