加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Delphi Chromium – 当用户点击网页中的按钮时,在Delphi应用程序

发布时间:2020-12-15 09:20:13 所属栏目:大数据 来源:网络整理
导读:我在Delphi应用程序中使用Chromium组件. 我想要以下行为: 当用户单击网页中的特定按钮时,Delphi应用程序(“容器”)必须执行命令(使用…启动外部可执行文件). 可能吗 ? 解决方法 更新: 由于您实际上已经为点击事件请求了DOM事件监听器,请检查以下示例监听G
我在Delphi应用程序中使用Chromium组件.

我想要以下行为:

当用户单击网页中的特定按钮时,Delphi应用程序(“容器”)必须执行命令(使用…启动外部可执行文件).

可能吗 ?

解决方法

更新:

由于您实际上已经为点击事件请求了DOM事件监听器,请检查以下示例监听Google搜索按钮单击事件(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',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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读