快速上手
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>
參考鏈接:
快速開始
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
博客園博客