How to handle javascript events via WebBrowser control for WinForms -


i have read webbrowser control .net — how inject javascript, is possible call javascript method c# winforms , many others. examples returns function value or alert window (synchronous calls). have result event handler (asyn call):

<script type="text/javascript">         window.onload = function() {             var o = new m.build(document.getelementbyid("zid"));              m.events.observe(o, o.events.success, function() {                 // have value!!             });              m.events.observe(o, o.events.fault, function() {                 // have value!!             });         }     </script> 

calling c# javascript

simply put, can expose c# object webbrowser javascript can call directly webbrowser class exposes property called objectforscripting can set application , becomes window.external object within javascript. object must have comvisibleattribute set true

c#:

 [system.runtime.interopservices.comvisibleattribute(true)]     public class scriptinterface     {         public void callme()         {             … // interesting         }     }      webbrowser1.objectforscripting = new scriptinterface(); 

javascript:

window.external.callme(); 

calling javascript in webbrowser control c#


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -