Given the following C# code:
public object CallJavaScriptFunction(string functionName, params object[] args)
{
object script = Document.Script;
var result = script.GetType().InvokeMember(functionName, BindingFlags.InvokeMethod, null, script, args);
return result;
}
And the following client-side JavaScript block:
function someFunction() {
alert('This is only a test!');
}
var someObj = {
someMethod: function() {
alert('This is another test!');
}
}
The following server-side block executes successfully:
CallJavaScriptFunction("someFunction");
But this will throw a DISP_E_UNKNOWNNAME:
CallJavaScriptFunction("someOBj.someMethod");
Obviously I'm doing somethi开发者_如何转开发ng wrong here - probably there is another way of calling InvokeMember
on JavaScript instance methods, but I was not able to find out how.
Any thoughts? Any help will be appreciated.
You need to invoke the someObj
property, then invoke the someMethod
method on the value of the property
精彩评论