Is it possible to call javascript from c# something like this?
ScriptRuntime py = Python.CreateRuntime();
dynamic random = py.UseFile("cal.js");
var result =random.Add(1,2);
cal.js
function Add(a, b) {
return (a + b);
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, as long as you host the js in a webrowser control. You can use the ObjectForScripting and document properties for this along with a com visible object. Indeed the opposite is true as well, that is you can call c# methods from JavaScript. The type dynamic allow you to pass, and work with, complex objects without having to use reflection Invoke/GetProperty, etc.
Here is a really simple example.