CyprUS
CyprUS

Reputation: 4239

Open new pages also in TWebBrowser

I have created an app with a twebBrowser in it. Problem is when i click on some link, in say gmail, it opens in a new window of my default browser( which is IE). how do i make it work like firefox or chrome etc. which opens the clicked links in their windows. The url's should open in the TWebBrowser's window. Must i create a new Form at runtime with TWebBrowser in it at runtime for that? Code not needed as such, ideas will do

Thanks in Advance.

P.S. My org blocks Gmail, Facebook etc. , However through my TWebBrowser, i can open them. Can my QA ppl see that in their log? My guess will be no, since then they would block it. What is your comment on this

Upvotes: 3

Views: 4643

Answers (1)

Cosmin Prund
Cosmin Prund

Reputation: 25678

TWebBrowser has an OnNewWindow2 event. Assuming the form holding the TWebBrowser is named Form1 and the web-control itself is named WebBrowser1, write a handler like this:

procedure TForm1.WebBrowser1NewWindow2(ASender: TObject; var ppDisp: IDispatch; var Cancel: WordBool);
var NF: TForm1;
begin
  NF := TForm1.Create(Application);
  NF.Visible := True;
  NF.WebBrowser1.RegisterAsBrowser;
  ppDisp := NF.WebBrowser1.DefaultInterface;
end;

This will create a new window, with a new TWebBrowser when the "click" is supposed to lead to a new window.

Upvotes: 5

Related Questions