新版本CefSharp.Winform 实现和js交互(JS调用C#方法) |
您所在的位置:网站首页 › cefsharp调用js方法 › 新版本CefSharp.Winform 实现和js交互(JS调用C#方法) |
CefSharp.Winform 要实现html页面中JS与C#方法调用。需要对被调用对象的Class进行注册; 以前的旧版本CefSharp这样注册(适用于79.0.0以前版本): RegisterJsObject //Old method(bound为前端被调用的对象名称.如:bound.login();BoundObject为C#被暴露的Class对象,对应的js调用的方法就是BoundObject.Login()) browser.RegisterJsObject("bound", new BoundObject(), options: BindingOptions.DefaultBinder);RegisterAsyncJsObject //Old Method browser.RegisterAsyncJsObject("boundAsync", new AsyncBoundObject(), options: BindingOptions.DefaultBinder);如果你下载的是79.0.0以上的新版本,那么使用以上方法会报以下错误,所以需要更换方法。 最新版本CefSharp需要这样注册(适用于79.0.0以后的版本): RegisterJsObject //(bound为前端被调用的对象名称.如:bound.login();BoundObject为C#被暴露的Class对象,对应的js调用的方法就是BoundObject.Login()) CefSharpSettings.LegacyJavascriptBindingEnabled = true; CefSharpSettings.WcfEnabled = true; browser.JavascriptObjectRepository.Register("bound", new BoundObject(), isAsync:false, options: BindingOptions.DefaultBinder);RegisterAsyncJsObject CefSharpSettings.LegacyJavascriptBindingEnabled = true; browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), isAsync: true, options: BindingOptions.DefaultBinder);管网示例来源:https://github.com/cefsharp/CefSharp/issues/2990
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |