js和C#互相调用

快速上手javascript

 

js和C#互相调用。

C#调用js比较容易。JS调用C#代码,现有两种方法。老方法的缺点是只支持单页,若是切换页面,原有建立的变量就失效了。新方法没有这些问题。html

老方法:

Cefsharp js调用c#与c#调用js

CefSharp 与 js 相互调用

新方法

https://github.com/cefsharp/CefSharp/issues/2246java

 

var options = new CefSharp.BindingOptions() {CamelCaseJavascriptNames = false}; var bindingOptions = options; //For async object registration (equivalent to RegisterJsObject) this.Browser.JavascriptObjectRepository.Register("boundAsync", new BoundObject(), true, options); this.Browser.JavascriptObjectRepository.Register("boundAsync2", new AsyncBoundObject(), true, options);
复制代码
<script type="text/javascript">
    function aa() { // <embed user provided code here> CefSharp.BindObjectAsync("boundAsync", "bound").then(function (result) { boundAsync.hello('CefSharp'); }); }; function bb(){ CefSharp.BindObjectAsync("boundAsync2").then(function(result) { boundAsync2.hello('CefSharp'); }); } </script>
复制代码

 

demo1git

 

参考连接:github

 

快速开始c#

https://github.com/cefsharp/CefSharp/wiki/Quick-Startasync

wpf中使用ide

https://www.codeproject.com/Articles/881315/Display-HTML-in-WPF-and-CefSharp-Tutorial-Partpost

官方demoui

https://github.com/cefsharp/CefSharp.MinimalExample

 博客园博客

https://www.cnblogs.com/M-Silencer/p/5846494.html

https://www.cnblogs.com/lonelyxmas/p/11397635.html

相关文章
相关标签/搜索