calling Javascript from c# using awesomium

后端 未结 2 739
半阙折子戏
半阙折子戏 2020-12-31 12:14

I\'m trying awesomium for create a basic app, I\'m testing the js <----> c# communication but this doesn\'t seem work well...I create a local html and open it..so far so

2条回答
  •  渐次进展
    2020-12-31 12:32

    This is a solution for Awesomium v1.7.0.5. It uses "JSObject" to get the javascript "window" object. From there it calls a javascript function that uses jQuery to dynamically set the text of a "div". This also uses jQuery to call the function when the document is ready.

    One can use the JSObject.Bind method to call C# methods from javascript.

    Head:

    
    

    Body:

    
    

    Test...

    C#:

    This uses WPF WebControl with Name of "webView" inside a Button Click event handler.

      using Awesomium.Core;
    
      ...
    
      private void Button1_Click(object sender, RoutedEventArgs e)
      {
         JSObject window = webView.ExecuteJavascriptWithResult("window");
    
         if (window == null)
            return;
    
         using (window)
         {
            window.InvokeAsync("setDivText", "You pressed button 1.");            
         }
      }
    

提交回复
热议问题