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);