Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In short you want c# to listen to javascript event! Nice.</p> <p>This is very easy using Awesomium.NET.</p> <p>After droping the awesomium control into your form it will by default create an object </p> <p>webControl1</p> <p>in the form_load method create a document.ready like event handler, the added event will be invoked when the document is ready</p> <pre><code>webControl1.DocumentReady += webControl1_DocumentReady; </code></pre> <p>lets create a javascript method from c# (say <code>myGlobalObject.myMethod(){ }</code> ). the script will be injected into the page by awesomium. we will then listen for the event where the function is called from javascript.</p> <p>you can even call this method from your <code>onPlayerStateChange</code></p> <pre><code>function onPlayerStateChange(event) { myGlobalObject.myMethod(); } </code></pre> <p>so that when your javascript event fires, it calls the javascript method <code>(myGlobalObject.myMethod();)</code> created in c#</p> <p>so we need to create the global object and then the associated method like this</p> <pre><code>using (JSObject myGlobalObject = webControl1.CreateGlobalJavascriptObject("myGlobalObject")) { // The handler is of type JavascriptMethodEventHandler. Here we define it // using a lambda expression. myGlobalObject.Bind("myMethod", true, (s, ee) =&gt; { // Provide a response. ee.Result = "My response"; }); } </code></pre> <p>this will carry out the necessary javascript object and method injection into your page. so</p> <p>in the webControl1_DocumentReady method (we attached earlier) then you can will have </p> <pre><code> void webControl1_DocumentReady(object sender, UrlEventArgs e) { dynamic myGlobalObject_ = (JSObject)webControl1.ExecuteJavascriptWithResult("myGlobalObject"); using (myGlobalObject_) { myGlobalObject_.myMethod = (JavascriptMethodEventHandler)OnCustomJavascriptMethod; } } </code></pre> <p>you will have to create the OnCustomJavascriptMethod method like this (for example)</p> <pre><code>private void OnCustomJavascriptMethod(object sender, JavascriptMethodEventArgs e) { MessageBox.Show("hi"); } </code></pre> <p>this method (OnCustomJavascriptMethod ) will be invoked in your c# when your javascript event onPlayerStateChange is invoked (because it will call myGlobalObject.myMethod();)</p> <p>thats all! wait for your onPlayerStateChange to fire and your method OnCustomJavascriptMethod(object sender, JavascriptMethodEventArgs e) in c# will be called, hence making javascript "control C# methods"</p> <p>you can find more information about awesomium at <a href="https://awesomium.com/" rel="nofollow">https://awesomium.com/</a> you can download the sdk for windows at <a href="http://awesomium.com/downloads/awesomium_1_7_0_sdk_win.exe" rel="nofollow">http://awesomium.com/downloads/awesomium_1_7_0_sdk_win.exe</a> and get started.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload