In this and the following two sections, we will look at the most common properties, methods, and events of the WebBrowser control and the InternetExplorer object. Most members apply to both, but the following sections focus on the members of the WebBrowser control.
Application This property returns the automation object where HTML documents are displayed (the Browser control or the InternetExplorer object). Busy This property returns a True/False value specifying whether the control is navigating to a new URL or is downloading a Web page. If the control’s Busy property is True for an unusually long time, call the Stop method to cancel the navigation or the download of a document.
Container This property returns an object that evaluates to the container of the WebBrowser control, if any. To find out the name of the container, use a statement such as the following:
This expression will return the name of the Form that contains the control.Document This property returns the automation object of the active document, if any. This is not. the Document object of the Scripting Model (which is covered later in this chapter), To access the document displayed on the control, you use the following expression:
This expression accesses the active document through the script property of the automation object. Later in this chapter, in the section “The IE Scripting Object Model,” you’ll learn how to manipulate the document from within your code (access its hyperlinks, for example, or even create a new document on the fly and display it on the WebBrowser control).
Height. Width These two properties return the dimensions, in pixels, of the control that contains the WebBrowser control.
Top, Left These two prope_rties return the location.in pixels, of the control’s upper-left comer on the Desktop.
LocationName. This property returns the title of the Web page displayed on the WebBrowser control.
LocationURL . This control returns the URL of the page displayed on the Web- Browser control. The LocationName and LocationURLproperties retrieve information about the location of the displayed document. If the location is an HTML page on the.World Wid~ Web, LocationName retrieves the page’s title, and LocationURL retrieves. the URL of that page. If the document displayed is a local file, both Locationl-lame and LocationURL retrieve the full path of the file (or i!s UNC, if it’s’Iocated on a network). Type “Ihis property returns a string that determines the type of the contained document object. The type for HTML documents is Windows HTML Viewer.
The Methods of the WebBrowser Control and the InternetExplorer Object.
The methods of the WebBrowSer control and the IntemetExplorer object let you navigate to new VRLs or to URLs already visited GoBack. GoForward These two methods navigate backward or forward QIleitem in the history list, which is maintained automatically by the WebBrowser control or the Internet explorer object. Attempting to move after the most recent .URLor before the first URL in the list generates a runtime error. To prevent this, you must include some error-trapping code, similar to the code you saw in the Explore application, earlier in this chapter. GoHome, GoSearch’ The Col-lome method navigates to the current home page; the GoSearch method navigates to the search page, as specified in the Internet Explorer Options dialog box Navigate This method navigates to a URL or opens an H1ML file, as specified in the method’s first argument.
This method has the following syntax: Navigate URL [Flags,] [TargetFrameName,]· [PostData,] [Headers] All the arguments except the first ate optional. The URLargument is the URL.of the resource to be displayed on the control. The Flags argument is a constant or a value that specifies whether to add the resource to the history list, whether to read from or write to the cache, and whether to display the resource in a new window. It can be a combination of the values
The TargetFrameName argument is the name of a frame in which the document will be displayed the document displayed on the WebBrowser control contains frames you can display the new document in one of the existing frames. . The PostData argument is a string to be sent to the server during the HITP POST transaction. The POST transaction is used to send data gathered on an HIML Form. U this parameter does not specify any post data, the Navigate method issues an H1TP GET transaction (it simply retrieves a document). This parameter is ignoIed if URLis not an HTTP URL (one whose protocol is HTTP). The HttIdds argument is a value that specifies additional HITP headers to be sent to the server. These headers are added to the default Internet Explorer headers, and they can specify such things as the action required of the server, the type of data being passed to the server, or a status code. This parameter is ignored if URL is not an H1TP URL.
Refresh This method reloads the page currently displayed on the WebBrowser control.
IIefntsh2 This method is similar to Refresh, but it lets yQUspecify the refresh level. It has the following syntax:
The level argument can have one of the values
In addition, you can prevent the control from using the cache by specifying the navNoReadFromCache and /lavNoWriteToCaclte flags when calling the Navigate method Stop This method cancels any pending navigation or download operation and stops playback of multimedia elements such as background sounds and animations.