Delphi Chromium - 当用户单击网页中的按钮时在 Delphi 应用程序中启动命令

标签 delphi button hyperlink tchromium

我在 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', 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 应用程序中启动命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10614187/

相关文章:

android:在 TextView 中使用 <a href> 设置链接

gcc 与 lex 配合良好,但在硬盘上找不到 libl.so

delphi - 列表框中的图像预览

delphi - 使用自定义样式时从未调用过表单销毁(OnDestroy)? XE7

android - 在 Activity 之间共享菜单栏

button - 从 VS 2012 导入设置后,Visual Studio 2013 缩进按钮变灰(不起作用)

javascript - Material-ui 从 react-router 添加到单选按钮组件的链接

delphi - 如何在delphi中从.pas文件安装组件?

c++ - C++结构到Delphi Record dll调用

android - 单击按钮时如何更新 ListView ?