SUMMARY
This article demonstrates a way to programmatically find
the
src attribute of a frame element from Visual Basic .NET when hosting
the WebBrowser control.
back to the top
Requirements
The following list outlines the hardware, software, network
infrastructure, and service packs that are required:
This article assumes that you are familiar with the following
topics:
- Visual Basic .NET
- Hosting WebBrowser control (Shdocvw.dll)
back to the top
Hosting the WebBrowser Control in Visual Basic .NET
- Open Visual Studio .NET, and create a new Visual Basic .NET
Windows application.
- On the Project menu, click Add reference, and then click the COM tab in the upper left of the window.
- Browse the list of COM components. Double-click to select Microsoft Internet Controls and Microsoft HTML Object Library, and then click OK.
- In the toolbox, right-click the Windows
form tab, and then click Customize toolbox. A small
dialog box appears. By default, the COM tab is selected. Again, browse the components list until you find
a component named Microsoft Web Browser, which points to Shdocvw.dll in your system32 directory. Select the Microsoft Web Browser check box, and then click OK.
- A new control named Explorer appears on the Windows form tab of your toolbox.
This is the WebBrowser control that you can place on the form.
When you complete these steps, browse in your Web browser to a
frameset page. Use the following code to obtain the
src attribute of each of the frames in the frameset.
NOTES: For this project to work, you must set a reference to
Microsoft HTML Object Library and
Microsoft Internet
Controls. If the code does not run, verify that these two components
are selected by reviewing steps 1 through 3.
back to the top
Complete Visual Basic .NET Code for Finding the src for Each Frame
- Place a button on the Form1.vb. In the Click event of the button, paste the following code:
Dim fDoc As MSHTML.IHTMLDocument
Dim x As Integer
fDoc = AxWebBrowser1.Document
For x = 0 To fDoc.All.length - 1
If fDoc.all.item(x).tagName = "FRAME" Then
MsgBox(fDoc.all.item(x).src)
End If
Next
fDoc = Nothing
- Run the application. After a frameset page is loaded,
click Button in the form to see the different src attributes of the different frame elements.
NOTE: The
src values that you see are based on the parent frameset page. If any
of the
src values is changed dynamically by client-side or server-side
script, you will not see these changes by using this method.
back to the top
Troubleshooting
As stated in the "Hosting the WebBrowser Control in Visual Basic
.NET" section, make sure that you added the
Microsoft HTML Object
Library and
Microsoft Internet Controls references to
the project.
back to the top
REFERENCES
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
back to the top