Opening the TWebBrowser link in the default browser

My application displays a small banner downloaded from the Internet in the control TWebBrowser. This banner is actually an HTML page that includes an image; when users click on the image that it takes to the advertising campaign that we are launching now.

It’s bad that when you click a link in TWebBrowser, the campaign page opens in Internet Explorer, and not in the default browser. I know this is happening because it TWebBrowseris an IE-based control, but is there a way to open the link in the user's browser of choice?

Thank.

+5
source share
2 answers

OnBeforeNavigate2 URL-, , , Stop() ShellExecute(), URL- .

procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject; pDisp: IDispatch; var URL: Variant; var Flags: Variant; var TargetFrameName: Variant; var PostData: Variant; var Headers: Variant; var Cancel: WordBool);
begin  
  if (URL should be launched) then
  begin
    Cancel := True;
    WebBrowser1.Stop;
    ShellExecute(0, nil, PChar(String(Url)), nil, nil, SW_SHOWNORMAL);
  end;
end;
+8

TWebBrowser DWebBrowserExents2:: NewWindow2 NewWindow2

procedure TForm1.WebBrowser1NewWindow2(
    ASender: TObject; var ppDisp: IDispatch; var Cancel: WordBool);

begin  
// create a new browser (e.g. hosted on a new tab /MDI form/ top level window)
// and expose the browser as a property of the new window. 
// Here a form2 object is created to host the new webbrowser instance
...
form2.InitNavigate=False;//the navigation will be triggered after this event
form2.Visible=False;//new window is only for getting the url
ppDisp := form2.WebBrowser1.Application;  
form2.Show;
end;

URL- BeforeNavigate2 form2. , ShellExecute .

SP SP2 , NewWindow3, URL- .

+3
source

All Articles