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.

Change popup target so it opens in the main frame?

Post Reply
marcio8501
Posts: 2
Joined: Wed Aug 03, 2022 3:53 pm

Change popup target so it opens in the main frame?

Post by marcio8501 »

I'm using CEF4Delphi to load a web app into a Delphi program. The web app only runs on a new tab (by design) after the user clicks a button that triggers some javascript code and eventually calls

Code: Select all

window.open('the_url','_newtab')
. CEF4Delphi opens a new window, so I use OnBeforePopup to stop the new window from opening while capturing the popup URL. I then open the URL from the main frame... it should work, but it fails (it redirects to the login screen when the URL is loaded in the main frame). Apparently the button that starts the web app also sets headers, cookies and other security-related properties, which are all lost when the new (simple) GET request occurs in the main frame.

Is there a way to just change the popup target so it opens in the main frame and not in a new window (keeping all request headers and stuff)?
User avatar
salvadordf
Posts: 4086
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Change popup target so it opens in the main frame?

Post by salvadordf »

Hi,

Yes. You can use a new tab or window for the new browser.

The TabbedBrowser2 demo has all the code to handle new popup browsers and new tabs. In your case I would use a new tab and then close or hide the previous browser.

See these functions :
  • TBrowserFrame.Chromium1BeforePopup
  • TMainForm.DoOnBeforePopup
marcio8501
Posts: 2
Joined: Wed Aug 03, 2022 3:53 pm

Re: Change popup target so it opens in the main frame?

Post by marcio8501 »

So, from your reply I gather that there's no other mechanism to just replace the target frame at any point after javascript:window.open is executed?

I'll give your suggestion a try. Thank you for taking the time to answer.
User avatar
salvadordf
Posts: 4086
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Change popup target so it opens in the main frame?

Post by salvadordf »

No. Changing the targetDisposition parameter in the OnBeforePopup event is not allowed.
At that point, Chromium expects to create a new browser and it's not possible to reuse the first one.

If you use the ResponseFilterBrowser demo you could modify the JavaScript code before it's executed in order to modify the target but that's a lot more complex than letting Chromium create a new browser in a new tab.
Post Reply