Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming that TCppWebBrowser is like TWebBrowser in Delphi, something like the code below should get you going.</p> <p>The <a href="http://www.cryer.co.uk/brian/delphi/twebbrowser/twebbrowser_events.htm" rel="nofollow noreferrer">OnBeforeNavigate2 event</a> gets fired before the TWebBrowser navigates to a new URL. What you do is cancel that navigation, and <a href="http://www.cryer.co.uk/brian/delphi/howto_openbrowserurl.htm" rel="nofollow noreferrer">redirect the URL with ShellExecute to an external application</a> (which is the default web browser as configured in Windows).</p> <p>In order to get the code below working, double click on your form, then enter the FormCreate event method content. Then drop a TWebBrowser, go do the events page of the object inspector and double click on the OnBeforeNavigate2 event and enter that code.</p> <p>Have fun with it!</p> <p>--jeroen</p> <pre><code>unit MainFormUnit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OleCtrls, SHDocVw; type TForm1 = class(TForm) WebBrowser1: TWebBrowser; procedure FormCreate(Sender: TObject); procedure WebBrowser1BeforeNavigate2(ASender: TObject; const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData, Headers: OLEVariant; var Cancel: WordBool); private RedirectUrls: Boolean; end; var Form1: TForm1; implementation uses ShellAPI; {$R *.dfm} procedure TForm1.Create(Sender: TObject); begin WebBrowser1.Navigate('http://www.stackoverflow.com'); RedirectUrls := True; end; procedure TForm1.WebBrowser1BeforeNavigate2(ASender: TObject; const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData, Headers: OLEVariant; var Cancel: WordBool); var UrlString: string; begin if not RedirectUrls then Exit; UrlString := URL; ShellExecute(Self.WindowHandle, 'open', PChar(UrlString), nil, nil, SW_SHOWNORMAL); Cancel := True; end; end. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload