Detecting TWebBrowser Update Event in Delphi 2009

I use the TWebBrowser component, which I use to load XML documents that are associated with the XSL file.

I have a default page displayed when loading an XML document. However, if the user deletes the XML file while it is open in the browser and then updates, I cannot find the standard resource . Instead, I would like the page not to load, check if the file exists, and if it doesn't just load the default page again.

I tried using OnNavigateError and OnBeforeNavigate2events, however they do not fire when updating.

Any idea?

+3
source share
2 answers

There is an onRefresh event that is displayed by replacing TWebBrowser TEmbeddedWB . This version also provides many other features that are otherwise hidden by the TWebBrowser component.

+1
source

This is a bit of a treasure, but it works in my tests using the standard TWebBrowser component.

I did an override of the F5 key in the form OnKeyUp. By KeyPreviewsetting the form property to True, you can invoke your own update. Since the TWebBrowser.Refresh method does not raise any navigation event (as you said in your question), I myself trigger the TWebBrowser.Navigate event, which fires events.

URL-, , , . , BeforeNavigate2 URL . . , F5 ( "", ), simpy URL-. OnBeforeNavigate2, OnNavigateComplete2 OnDocumentComplete , - IE.

procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject;
  const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
  Headers: OleVariant; var Cancel: WordBool);
begin
  Edit1.Text := URL;
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_F5) then
  begin
    WebBrowser1.Navigate(Edit1.Text);
  end;
end;
0

Source: https://habr.com/ru/post/1724946/


All Articles