Rank: Member Groups: Member
Joined: 11/13/2014 Posts: 13
|
Is this the only way to call a .NET method from JS: //Invoke JavaScript "extension" "demoAbout" with a single argument eoWebBrowser.extInvoke("demoAbout", [window.navigator.appVersion]);
For example, if I have a few .NET classes that I want to call methods on, i will have to create a wrapper class to receive the call, then make the calls to the other objects. Is there a way I can reference the .NET class directly in JS? So I can do something like:
<script type="text/javascript">
function myMethod() { document.write("In myMethod, calling .NET but expecting no return value.<br/>");
netObj.calculateDistance(); } </script>
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
Currently you can't do that out of box. But it's possible for you to use reflection to generate a wrapper JavaScript class of your .NET class and inject the JavaScript class into the WebView either through WebView.JSInitCode property or WebView.EvalScript. After that the wrapper class will be available to your JavaScript code. We did not implement this due to performance concerns ---- crossing between the JavaScript "World" and the .NET "World" is a relatively expensive operation. As such while automatically allowing you to call .NET side objects is indeed very convenient, it can quickly downgrade the performance significantly. Thus we still recommend you to use extInvoke so that you can limit the number of cross boundary calls.
Thanks!
|