2005. december 14., szerda
How to open an URL in a regular browser instead of opening it in a TWebBrowser
Problem/Question/Abstract:
I have a TWebBrowser in my application that loads unknown remote content. When a user clicks on any link in it, I would like to have the URL opened in a regular browser, but not within the TWebBrowser itself. I do not want the TWebBrowser to act upon the click.
Answer:
Use the OnBeforeNavigate2 event like that:
procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject; const pDisp: IDispatch;
var URL, Flags, TargetFrameName, PostData, Headers: OleVariant; var Cancel: WordBool);
begin
if not FManuallyLoading then
begin
{Stop Loading in this Browser ...}
Cancel := True;
{... but open in new Browser}
Flags := Flags or 1;
(Sender as TWebBrowser).Navigate(WideString(URL), Flags,
TargetFrameName, PostData, Headers);
end;
end;
Set FManuallyLoading to True, while you are programmatically loading content into the web browser:
procedure TForm1.Button1Click(Sender: TObject);
begin
FManuallyLoading := True;
WebBrowser1.Navigate('http://www.nineberry.de');
FManuallyLoading := False;
end;
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése