• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

delphiScriptGate调用JS

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

在 FireMonkey 使用 TWebBrowser 调用 Javascript函数并获取返回值以及 JavaScript 中调 Delphi 的函数/过程,普遍都在使用老掉牙的URL重定的方法,还要改 FMX 的源码,相当繁琐。

现在使用 ScriptGate 可轻易解决这个问题,ScriptGate  支持 Windows, macOS, Android, iOS,非常好用,强烈推荐。

项目地址:https://bitbucket.org/freeonterminate/scriptgate

 用法如下:

HTML / JavaScript:



Call Delphi procedure ;

Delphi:
procedure TForm1.FormCreate(Sender: TObject);
begin
// Binding ScriptGate to WebBrowser and setting the scheme delphi
// The scheme is also specified on the JavaScript side
// Same as file :, JavaScript: etc.
ScriptGate := TScriptGate.Create(Self, WebBrowser1, 'delphi');
end;

// Call helloJS () JavaScript.
// You can also retrieve the return value using an anonymous function.
procedure TForm1.Button1Click(Sender: TObject);
begin
FScriptGate.CallScript(
'helloJS()',
procedure(const iResult: String)
begin
ShowMessage(iResult); // Show return value
end
);
end;

// Execute arbitrary JavaScript
// You can also retrieve the return value using an anonymous function.
procedure TForm1.Button1Click(Sender: TObject);
begin
FScriptGate.Eval(
'document.getElementsByTagName("html")[0].outerHTML',
procedure(const iResult: String)
begin
ShowMessage(iResult); // Show return value
end
);
end;

// It is a method published in JavaScript and is called from JavaScript.
procedure TForm1.HelloDelphi;
begin
ShowMessage('Hello, Delphi!');
end;


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap