Chromimu与JS交互的测试
来源:互联网 发布:ipad手写板软件 编辑:程序博客网 时间:2024/04/29 04:27
测试一
为解决ExecuteJavascript无法得到返回值的问题,尝试采用JS Dialog和OnJsDialog的方法。
测试结果:可以采用此法传递Js的结果值。
JS
alter('abc');
confirm('abc');
DELPHI
procedure TForm1.ChromiumFMXJsdialog(Sender: TObject;
const browser: ICefBrowser; const originUrl, acceptLang: ustring;
dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring;
callback: ICefJsDialogCallback; out suppressMessage, Result: Boolean);
begin
case dialogType of
TCefJsDialogType.JSDIALOGTYPE_ALERT: self.Caption:='ALTERT:' + messageText;
TCefJsDialogType.JSDIALOGTYPE_CONFIRM: self.Caption:='CONFIRM:' + messageText;
end;
Result:=true;
end;
测试二
JS调用Delphi自定义的方法。
测试结果:
1. 可以成功调用;
2. JS可以接收到Delphi方法的返回值;
3. JS的输入参数长度,65214*9是没问题的,更长的长度没有做测试。
TTestExtension = class
class function addTask(songnumber: string): boolean;
end;
TCustomRenderProcessHandler = class(TCefRenderProcessHandlerOwn)
protected
procedure OnWebKitInitialized; override;
end;
class function TTestExtension.addTask(songnumber: string): boolean;
begin
showmessage('addTask:' + songnumber);
// result:= (songnumber.Substring(0,1)='1') or //JS可接收该返回值
// (songnumber.Substring(0,1)='2') ;
end;
procedure TCustomRenderProcessHandler.OnWebKitInitialized;
begin
TCefRTTIExtension.Register('app', TTestExtension);
end;
initialization
CefRemoteDebuggingPort := 9000;
CefRenderProcessHandler := TCustomRenderProcessHandler.Create;
CefBrowserProcessHandler := TCefBrowserProcessHandlerOwn.Create;
用默认浏览器打开Chromium页面中的"_blank"超链。
测试结果:
1. 可以在delphi中捕获超链的点击事件,用自定义的方法来替代Chromium原生的浏览器小窗口。
2. 在delphi中返回False给Js,或者在Js中直接return false,都可以阻止Chromium原生小窗口的打开。
JS
$(document).ready(function(){
$("a[target=_blank]").click(function(event){
var href = $(this).attr("href");
return app.doClickHyperlink(href);
//return false;
});
DELPHI
TTestExtension = class
class function doClickHyperlink(href: string): boolean;
end;
class function TTestExtension.doClickHyperlink(href: string): boolean;
begin
result:=ShellExecute(0, 'Open', PChar(href), nil,nil,1)<0; //返回False给JS,以阻止Chromium原生的浏览器小窗口。
end;
- Chromimu与JS交互的测试
- js与Fckeditor的交互
- SVG与JS的交互
- js与as的交互
- js与as3的交互
- PHP 与 js 的交互
- Java与js的交互
- SVG与JS的交互
- WebView与js的交互
- js与webView的交互
- JS与UIWebView的交互
- UIWebView与JS的交互
- UIWebView与JS的交互
- OC与JS的交互
- Android 与 js 的交互
- js与后台的交互
- WebView 与 JS 的交互
- UIWebView与JS的交互
- ice mac 安装2
- Eclipse导入android项目出现很多错误
- Delete Node in a Linked List 删除链表中的某个节点
- heX:用HTML5和Node.JS开发桌面应用
- KEIL下S3C2440裸机开发
- Chromimu与JS交互的测试
- c语言文件操作
- Cocos2d-lua 3.10 图片资源加密
- 单调栈应用
- IDEA使用
- 搜索策略
- Could not launch “ ”,process launch failed: Security解决
- spring boot 入门
- 安卓网络请求框架okHttp的使用与封装