Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Opening new tab

Post Reply
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Opening new tab

Post by andreykrasnodar »

Is there a possibility to open links with target="_blank" in a new tab, not in a new window?
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Re: Opening new tab

Post by andreykrasnodar »

I tried to make 2 tabs with 2 ChromiumOSR browsers named Chromium1 and Chromium2 and type this

Code: Select all

procedure TForm1.Chromium1BeforePopup(Sender: TObject;
  const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
  targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
  userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
  var windowInfo: TCefWindowInfo; var client: ICefClient;
  var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
  out Result: Boolean);
var
  Header: ICefStringMultimap;
  Request: ICefRequest;
  Data: ICefPostData;
begin
  showmessage('trying to open a new tab');
  Result:=True;
  Header := TCefStringMultimapOwn.Create;
  Request := TCefRequestRef.New;
  Header.Append('Referer', Frame.Url);
  Request.Assign(targetUrl, '', nil, Header);
  Chromium2.Browser.MainFrame.LoadRequest(Request);
  ShowMessage('has opened');
end;
but application hangs.
User avatar
salvadordf
Posts: 4575
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Opening new tab

Post by salvadordf »

Try cancelling the new popup window setting "result" to true, saving the targetUrl value and sending a windows message to the main form to use the targetUrl value as parameter in Chromium2.Load.

Remove the "showmessage" or any other function that creates, destroys or modifies VCL controls inside cef events because they are executed in a different thread and the VCL is not thread safe.

Please, consider using cef4delphi instead of dcef3. There're multiple demos and many bugs in chromium, cef and dcef3 were fixed.
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Re: Opening new tab

Post by andreykrasnodar »

Try cancelling the new popup window setting "result" to true
I have already done it (the code ^)
Remove the "showmessage" or any other function that creates, destroys or modifies VCL controls inside cef events because they are executed in a different thread and the VCL is not thread safe.
Thanks. It helps.
Please, consider using cef4delphi instead of dcef3. There're multiple demos and many bugs in chromium, cef and dcef3 were fixed.
My software is for windows xp. So I have to use old CEF
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Re: Opening new tab

Post by andreykrasnodar »

I have found an answer!!!!!

Code: Select all

procedure TForm1.Chromium1BeforePopup(Sender: TObject;
  const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
  targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
  userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
  var windowInfo: TCefWindowInfo; var client: ICefClient;
  var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
  out Result: Boolean);
var
  Header: ICefStringMultimap;
  Request: ICefRequest;
  Data: ICefPostData;
begin
  Result:=True;
  Request := TCefRequestRef.New;
  Request.Url := targetUrl;
  Request.Method := 'POST';
  Header := TCefStringMultimapOwn.Create;
  Header.Append('Referer', Frame.Url);
  Request.SetHeaderMap(Header);
  Data := TCefPostDataRef.New;
  Request.PostData := Data;
  Chromium2.Browser.MainFrame.LoadRequest(Request);
  chromium1.Browser.Host.SendFocusEvent(false);
  chromium2.Browser.Host.SendFocusEvent(True);
end;
It works PERFECT!!!
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Re: Opening new tab

Post by andreykrasnodar »

andreykrasnodar wrote: Sat Aug 08, 2020 10:03 am I have found an answer!!!!!

Code: Select all

procedure TForm1.Chromium1BeforePopup(Sender: TObject;
  const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
  targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
  userGesture: Boolean; var popupFeatures: TCefPopupFeatures;
  var windowInfo: TCefWindowInfo; var client: ICefClient;
  var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean;
  out Result: Boolean);
var
  Header: ICefStringMultimap;
  Request: ICefRequest;
  Data: ICefPostData;
begin
  Result:=True;
  Request := TCefRequestRef.New;
  Request.Url := targetUrl;
  Request.Method := 'POST';
  Header := TCefStringMultimapOwn.Create;
  Header.Append('Referer', Frame.Url);
  Request.SetHeaderMap(Header);
  Data := TCefPostDataRef.New;
  Request.PostData := Data;
  Chromium2.Browser.MainFrame.LoadRequest(Request);
  chromium1.Browser.Host.SendFocusEvent(false);
  chromium2.Browser.Host.SendFocusEvent(True);
end;
It works PERFECT!!!
But sometimes it is a problem named APPCRASH in module libcef.dll 3.2454.1344.0 at 00186429. External exception 80000003.
Post Reply