快速上手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
博客園博客