Welcome Guest Search | Active Topics | Sign In | Register

Calling .NET methods from JavaScript Options
crenzi
Posted: Thursday, November 13, 2014 11:25:10 AM
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>
eo_support
Posted: Thursday, November 13, 2014 12:08:15 PM
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!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.