Delphi Chromium - launch a command in a Delphi application when a user clicks on a web page by a user

I am using the Chromium component in a Delphi application.

I would like the following behavior:

When a user clicks a specific button on a web page, the Delphi application ("container") must execute the command (start an external executable file with ...).

Is it possible?

+4
source share
1 answer

Update:

Since you really asked for a DOM event listener for click events, check out the following example while listening for the Google search button click event (element with gbqfba ):

 uses ShellAPI, cefvcl, ceflib; procedure TForm1.Button1Click(Sender: TObject); begin Chromium1.Load('www.google.com'); end; procedure OnClickEvent(const AEvent: ICefDomEvent); begin ShellExecute(Form1.Handle, nil, 'notepad.exe', nil, nil, SW_SHOWNORMAL); end; procedure OnExploreDOM(const ADocument: ICefDomDocument); var DOMNode: ICefDomNode; begin DOMNode := ADocument.GetElementById('gbqfba'); if Assigned(DOMNode) then DOMNode.AddEventListenerProc('click', True, OnClickEvent); end; procedure TForm1.Chromium1LoadEnd(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer; out Result: Boolean); begin if Assigned(frame) then begin // here you should check the frame.Url to verify if you're on the right URL // before you try to search for the element and attach the event if found frame.VisitDomProc(OnExploreDOM); end; end; 
+7
source

All Articles