DCEF3 - Delphi Chromium Embedded - communication between Javascript and application code

强颜欢笑 提交于 2019-12-04 09:31:37

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

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

A quite easy workaround is to catch the browser's OnJSDialog / OnConsoleMessage event, do an Alert/log in JS when there's something to execute. Tell the delphi part in the alert's message what to do. You need to interpret it as a string (maybe with a scripting library or direct parsing). No direct call of delphi code is possible with it, but I guess it's safer this way anyway.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!