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.

How to open _blank link in the same window?

Post Reply
nimq
Posts: 10
Joined: Thu May 09, 2019 10:11 pm

How to open _blank link in the same window?

Post by nimq »

Hello!

I need links that usually open in a new tab to always open in the same window

In older versions, I used the following code at Chromium_OnBeforePopup

Code: Select all

    case targetDisposition of
      CEF_WOD_CURRENT_TAB,
      CEF_WOD_SINGLETON_TAB,
      CEF_WOD_NEW_FOREGROUND_TAB,
      CEF_WOD_NEW_BACKGROUND_TAB,
      CEF_WOD_NEW_WINDOW,
      CEF_WOD_NEW_POPUP:
        begin
          ChromiumWindow1.ChromiumBrowser.StopLoad;
          req := TCefRequestRef.New;
          req.Url := targetUrl;
          req.Method := 'GET';
          req.Flags := UR_FLAG_ALLOW_STORED_CREDENTIALS;
          req.SetReferrer(frame.Url, REFERRER_POLICY_NEVER_CLEAR_REFERRER);
          ChromiumWindow1.ChromiumBrowser.LoadRequest(req);
          Result := true;
        end;
    else
      Result := False;
    end;
but it doesn't work now :(

How to achive what i need?

Thanks!
User avatar
salvadordf
Posts: 4304
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to open _blank link in the same window?

Post by salvadordf »

Hi,

Try calling ChromiumWindow1.LoadURL(targetUrl) instead of using LoadRequest because that function may fail with bad IPC message reason INVALID_INITIATOR_ORIGIN (213) unless you first navigate to the request origin using some other mechanism (LoadURL, link click, etc).
nimq
Posts: 10
Joined: Thu May 09, 2019 10:11 pm

Re: How to open _blank link in the same window?

Post by nimq »

Hello!

if we use the LoadURL method everything works as expected, but the header is different - the referer is not being passed.

Is it possible to add a referer field when loading through LoadURL?
User avatar
salvadordf
Posts: 4304
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to open _blank link in the same window?

Post by salvadordf »

Here's an example to add or replace an HTTP header :
https://github.com/salvadordf/CEF4Delphi/blob/16f76f39aa2cb898a587b15bb39367e077bd9e6d/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L1229

Consider using a TPageControl like the TabbedBrowser2 demo. You can hide the tabs and select the new browser tab automatically.
Post Reply