Page 1 of 1

how to open a new window with a button

Posted: Mon Apr 22, 2024 2:23 pm
by bobpang
Hi,
I have a problem that I need your help,is about How to click a button in a delphi VCL form and open it in a pop-up window, similar to clicking a hyperlink with newtarget like

Code: Select all

<a href="https://google.com" target="_blank">open</a>

Re: how to open a new window with a button

Posted: Mon Apr 22, 2024 6:16 pm
by salvadordf
Hi,

If the button is used to submit some data in a <FORM> html element using the POST method then you'll have to simulate a mouse click over the button. Try sending WM_LBUTTONDOWN and WM_LBUTTONUP to TChromium.RenderHandle. If that fails you can use a browser in OSR mode and then call TChromium.SendMouseClickEvent.
https://github.com/salvadordf/CEF4Delphi/blob/82f6d8eeb6a6cf5fa09822c4b651322504e470a6/demos/Delphi_VCL/SimpleOSRBrowser/uSimpleOSRBrowser.pas#L950
https://github.com/salvadordf/CEF4Delphi/blob/82f6d8eeb6a6cf5fa09822c4b651322504e470a6/demos/Delphi_VCL/SimpleOSRBrowser/uSimpleOSRBrowser.pas#L884

For other situations you can use the code in the ToolBoxBrowser demo.

Re: how to open a new window with a button

Posted: Tue Apr 23, 2024 12:35 am
by bobpang
In ToolBoxBrowser demo, how do I click the open button and open the link using the default form instead of ChildForm? Just like clicking on the a tab in html, a new form opens and displays it.

Re: how to open a new window with a button

Posted: Wed Apr 24, 2024 9:44 am
by salvadordf
Use the TChromiumCore.OnBeforePopup event and check the targetDisposition value like this :
https://github.com/salvadordf/CEF4Delphi/blob/82f6d8eeb6a6cf5fa09822c4b651322504e470a6/demos/Delphi_VCL/SimpleBrowser2/uSimpleBrowser2.pas#L140

Setting the Result argument to True blocks all popup windows and new tabs.

The simply call TChromiuCore.LoadURL(targetUrl); to navigate using the same browser.

Re: how to open a new window with a button

Posted: Thu Apr 25, 2024 2:29 pm
by bobpang
thank you