DCEF3-Delphi Chromium Embedded-Javascript与应用程序代码之间的通信 [英] DCEF3 - Delphi Chromium Embedded - communication between Javascript and application code

查看:252
本文介绍了DCEF3-Delphi Chromium Embedded-Javascript与应用程序代码之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DCEF3,修订版24038bd3a600,我应该在浏览器中的Javascript代码与应用程序的Delphi代码之间进行通信。
我知道如何使用框架的 ExecuteJavascript方法从Delphi代码和Javascript中实现,但是相反(从Javascript到Delphi /应用程序代码)呢?
我没有在演示/示例中找到这种情况(特别是GUIclient)。

I'm using DCEF3, revision 24038bd3a600, and I should want to communicate between Javascript code in browser and Delphi code of application. I know how it can be accomplished from Delphi code and Javascript, by using framework's method 'ExecuteJavascript', but what about the reverse (from Javascript to Delphi/application code) ? I haven't found such a situation in demos/examples (GUIclient, specifically...).

推荐答案

如果有官方源代码,则有一个 guiclient 演示。查看 main.pas 文件。

There is a guiclient demo if official source code to do this. Look at main.pas file.

下面的代码是一个类扩展:

The code below is a class extension :

class function TTestExtension.hello: string;
begin
  Result := 'Hello from Delphi';
end;

下面的代码注册扩展类:

The code below register the extension class :

TCefRTTIExtension.Register('app', TTestExtension);

以下代码从HTML页面调用您的本机代码:

The code below call your native code from a HTML page :

<script>
alert ( app.hello() );
</script>

以下代码从嵌入式浏览器调用您的本机代码:

The code below call your native code from embedded browser :

crm.Browser.MainFrame.ExecuteJavaScript('alert ( app.hello() );', 'about:blank', 0);

这篇关于DCEF3-Delphi Chromium Embedded-Javascript与应用程序代码之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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