Write an OnNavigateComplete2 event handler to take an
action when the browser successfully navigates to a new resource. The event
can occur before the document is fully downloaded, but when it occurs at least
part of the document must be received and a viewer for the document
created.
|
Note:
|
Unlike the OnDownloadComplete event, OnNavigateComplete2
does not occur if the operation is not successful.
|
Command Arguments:
Sender
- The TWebBrowser component for which the event is being generated. Usage:
(Sender as TWebBrowser)
pDisp
- The IWebBrowser component for which the event is being generated. Usage:
(pDisp as IWebBrowser)
URL
- The URL that has been navigated to.
Example of navigating to your own error page:
procedure TForm1.EmbeddedWB1NavigateComplete2(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); var dir: array [0..MAX_PATH] of Char; begin GetSystemDirectory(dir, MAX_PATH); if AnsiUpperCase(StrPas(dir)+'\shdoclc.dll') = AnsiUpperCase((EmbeddedWB1.document as IHTMLDocument2).location.hostname) then EmbeddedWB1.Navigate('MyError.html'); end;
Example of using OnNavigateComplete2 event by Zarko Gajic, to preview MS Wird documents:
If you decided to use (Microsoft) Word as a "printing engine" for your applications, you will probably want to have some kind of print and print preview functionality.
Here's how to use the TWebBrowser control to preview and print Microsoft Word documents.
Drop a TEmbeddedWB (name: EmbeddedWB1) on a Form and assign the next code for the NavigateComplete2 event handler:
~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TWordPreviewForm.FormCreate(Sender: TObject) ;
begin
//open a Word document in WebBrowser
EmbeddedWB1.Navigate('c:\SomeFolder\SomeDocument.doc') ;
end;
procedure TWordPreviewForm.EmbeddedWB1NavigateComplete2(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant) ;
begin
with (EmbeddedWB1.Document AS _Document) do
begin
ActiveWindow.View.ShowAll := False;
ActiveWindow.View.TableGridlines := False;
ActiveWindow.DisplayRulers := False;
ActiveWindow.View.type_ := wdPageView;
end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
The code in the above handler sets the "view type" to "Print layout",
hides all non-printing characters (bookmarks, tab characters, etc.),
hides table grid lines, and hides rulers.
|