I'm using a TWebBrowser
to display some HTML content (locally). The application is split in half, the top half has 5 tabs and the bottom half is the web browser. The contents of the browser change often, for example when changing to a different tab.
The content which is shown includes URLs which I need to prevent and stop every click. I'm trying to use the event OnBeforeNavigate2
which does detect every link clicked, but also detects when I programatically call Navigate
. So, it winds up never navigating anywhere.
I tried wrapping the Navigate
call so I always call something like...
procedure TForm1.Nav(const S: String);
begin
FLoading:= True;
try
Web.Navigate(S);
Sleep(50);
finally
FLoading:= False;
end;
end;
(Sleep was just to try and give it a split second to wait)
And then capturing the call...
procedure TForm1.WebBeforeNavigate2(ASender: TObject; const pDisp: IDispatch;
const URL, Flags, TargetFrameName, PostData, Headers: OleVariant;
var Cancel: WordBool);
begin
if not FLoading then
Cancel:= True;
end;
No luck trying this trick. How can I detect when the page or user navigates but not when the browser is instructed to navigate?