惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Last Week in AI
Last Week in AI
Project Zero
Project Zero
L
LINUX DO - 最新话题
C
Cisco Blogs
P
Privacy International News Feed
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Security @ Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
V
Vulnerabilities – Threatpost
W
WeLiveSecurity
Webroot Blog
Webroot Blog
K
Kaspersky official blog
Help Net Security
Help Net Security
博客园_首页
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
雷峰网
雷峰网
The Last Watchdog
The Last Watchdog
WordPress大学
WordPress大学
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
A
Arctic Wolf
I
Intezer
V
V2EX
博客园 - 【当耐特】
Latest news
Latest news
T
Tenable Blog
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
Cyberwarzone
Cyberwarzone
量子位
G
GRAHAM CLULEY
T
Troy Hunt's Blog
博客园 - Franky
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - 三生石上(FineUI控件)
TaoSecurity Blog
TaoSecurity Blog
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
Jina AI
Jina AI
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Scott Helme
Scott Helme

博客园 - 雪夜

VS统计代码量 DataTable 操作 - 雪夜 - 博客园 统计销售额 bootstrap 知识点 人脸识别 参考 转盒子 年龄段统计 model 数据注解 C#区块链零基础入门,学习路线图 转 SQLServer 2005 和自增长主键identity说再见——NEWSEQUENTIALID() ASP.NET Core and .NET Core Library Support 创新县(市、区)的主要条件 C# imgage图片转base64字符/base64字符串转图片另存成 base64编码的 文件 图片 CSS - 雪夜 - 博客园 Exception has been thrown by the target of an invocation 网站报错 高效通用分页存储过程 多表查询 JavaScript 知识记录 JQuery 全选 取消 博文阅读密码验证 - 博客园
delphi ScriptGate 调用JS
雪夜 · 2018-03-13 · via 博客园 - 雪夜

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