Delphi Chromium - launch a command in Delphi application when button in web page is clicked by user

后端 未结 1 1968
猫巷女王i
猫巷女王i 2021-01-03 06:40

I\'m using Chromium component in a Delphi application.

I\'d like the following behaviour:

When user clicks a specific button in a web page, the Delphi applic

相关标签:
1条回答
  • 2021-01-03 07:36

    Update:

    Since you've actually asked for DOM event listener for click events, check the following example listening the Google search button click event (the element with ID 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;
    
    0 讨论(0)
提交回复
热议问题