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 a new window with a button

Post Reply
bobpang
Posts: 12
Joined: Fri Feb 14, 2020 2:38 pm

how to open a new window with a button

Post 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>
User avatar
salvadordf
Posts: 4067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how to open a new window with a button

Post 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.
bobpang
Posts: 12
Joined: Fri Feb 14, 2020 2:38 pm

Re: how to open a new window with a button

Post 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.
User avatar
salvadordf
Posts: 4067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how to open a new window with a button

Post 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.
bobpang
Posts: 12
Joined: Fri Feb 14, 2020 2:38 pm

Re: how to open a new window with a button

Post by bobpang »

thank you
Post Reply