Page 1 of 1

Change popup target so it opens in the main frame?

Posted: Wed Aug 03, 2022 4:43 pm
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)?

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

Posted: Thu Aug 04, 2022 3:57 pm
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

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

Posted: Thu Aug 04, 2022 5:15 pm
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.

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

Posted: Thu Aug 04, 2022 5:55 pm
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.