The Events of the Web Browser Control and the Internet Explorer Object VB Help

The events of the WebBrowser and the InternetExplorer object are triggered each time the user moves to another URL with Internet Explorer’s navigation buttons or the WebBrowser control’s navigation methods. They also monitor the progress of each download and let your application know when the download of a page is finished.

BeforeNavigate2 This event occurs when the WebBrowser control is about to navigate to ,a different URL. It can be caused by external automation (by calling its Navigate method) or by internal automation from within a script or when the. user clicks a hyperlink in the current document. Your application has an opportunity· to cancel the navigation by setting the method’s Cancel argument to True;

TIle first argument, pDisp, represents the object on which the document is displayed. Since this object is usually the WebBrowser control, you can use this argument to access the properties of the control. pDisp.Name is its name, pDisp .Width and pDisp.Height are the control’s dimensions, and so on. The URL argument is the destination URL, (specified by the Navigate method orin the hyperlink that was clicked), and Flags is a reserved argument. The TtzrgetFrame Name argument is the name of the frame in which to display the specified document, or it is NULL if the document is to appear on the control, outside any frames. The Post Data and Header arguments are the same as for the Navigate method,

The application can set the Cancel argument (notice that it’s passed by reference] to cancel the navigation process. If you set this argument to Troe, the naviS-tion won’t even start. To stop a navigation process in progress, use the Stop NavigateComplete This event occurs after the control has successfully navigated to the new location. Some of the document’s resources may still be downloading (a large image, for instance, may take quite a while), but at least part of the document has been received from the server, and progressive rendering bas started already. To interrupt this process, you must call the Stop method.

Download begin This event occurs when a navigation operation is beginning & It’s triggered shortly after the BeforeNavigate event (unless the navigation was canceled), and it.signals your application to display a bUsy message or change the pointer’s shape. The DownloadBegin event has the following declaration.

Sub WebBrowser1-DownloadBegin ()

DownloadComplete. This event occurs when a navigation operati<* is finished, hal, or failed. Unlike NavigateComp1etei which may nOt be triggered the navigation doesn’t complete successfully, this event is always triggered after a navigation starts. Any busy indication by your application must end from within this event. The’OownloadComplete event has the following declaration:

ProgressChange The WebUrowser control tracks the progress of a download operation and~odically issues the ProgressChange event to inform your application of the progress. The ProgxessChaitge event has the following decJanltion:

Both arguments are long integers. The Progress argument is the amount of data. downloaded so far, and ProgrtssMax is the total amO\D\t of data to be downloaded .

TItIe change This event occurs when the title of the current document changes. The title of an HIML document can change; while the document is being downloaded, the URL of the document is also its title. After the real title (if one was specified with the 1TI1..E tag) is parsed, the TItleChange event is triggered, ana you can use it to update the Caption property on your VisualBasic. The TItleChange event has the following declaration:

Sub WebBrowsenl_TitleChange(ByVal Text As String)

The Text argument is the string that appears in Internet Explorer’s caption bar.

NewWlndow .Although most hyperlinks result in updating the same window in which the document with the hyperlink is displayed, some hyperlinks specify that a new window be opened to display the destination document. When a new window iSlIbout to be created for displaying a new document, the New Wmdow ,event is triggeredus event can be also be triggered if the user holds down the Shift key and clicks the mouse while the cursor is over a hyperlink or if the user chooses New Window > Open in the hyperlink’s shortcut menu. The NewWmdow event gives your application the opportunity to halt the creation of the new window. When this event is used with Internet Explorer, the new window is another instance of Internet Explorer. “\ When the NewWmdow event is used with the WebBrowser control, however, your application must either create a new WebBrowser control and display the document there or request that the new document be displayed in the same window. If your ‘application creates a new WebBrowser .control, it must pass all the parameters from the NewWmdow event directly to the Navigate method on the newly created WebBrowser control. If you decide to display the new document on the same control, you must again pass the parameters from this event to the Navigate meth04,in the existing window.

The argUments’ of the New W event are identical to the arguments of the Navigate method, except for the last argument which is a True/False value indicating whether your application will create the new window (set it to True) or not (set it to False).

Posted on November 6, 2015 in Visual Basic and the Web

Share the Story

Back to Top