js和C#互相調用


快速上手

 

js和C#互相調用。

C#調用js比較容易。JS調用C#代碼,現有兩種方法。老方法的缺點是只支持單頁,如果切換頁面,原有創建的變量就失效了。新方法沒有這些問題。

老方法:

Cefsharp js調用c#與c#調用js

CefSharp 與 js 相互調用

新方法

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

 

  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>
復制代碼

 

demo1

 

參考鏈接:

 

快速開始

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

wpf中使用

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

官方demo

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

 博客園博客

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

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM