Delphi Chromium - 当用户单击网页中的按钮时,在 Delphi 应用程序中启动命令 [英] Delphi Chromium - launch a command in Delphi application when button in web page is clicked by user

查看:44
本文介绍了Delphi Chromium - 当用户单击网页中的按钮时,在 Delphi 应用程序中启动命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Delphi 应用程序中使用 Chromium 组件.

I'm using Chromium component in a Delphi application.

我想要以下行为:

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

When user clicks a specific button in a web page, the Delphi application (the 'container') must execute a command (launch an external executable with ...).

有可能吗?

推荐答案

更新:

由于您实际上已经要求 DOM 事件侦听器用于点击事件,请查看以下示例来侦听 Google 搜索按钮点击事件(ID gbqfba 的元素):

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;

这篇关于Delphi Chromium - 当用户单击网页中的按钮时,在 Delphi 应用程序中启动命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆