views:

266

answers:

2

I am trying to use InvokeScript method on the WebBrowser control to execute a script on the web page that has been loaded into my WebBrowser control. If I am calling just a simple javascript function, this works properly. However, the javascript function that I am trying to call is nested within a variable like this:

var holder = { DoA: function() { .... }, DoB: function() { ..... } }

Calling holder.DoA works fine when called from within the javascript, but the function is not called successfully when I try to call it from within my C# code like this:

object obj1 = m_webBrowser.Document.InvokeScript("holder.DoA");

Any ideas?

A: 

Have you tried window.holder.DoA as the parameter to InvokeScript ?

Timores
I tried this and it still did not work:m_webBrowser.Document.InvokeScript("window.holder.DoA");
A: 

That's a singleton JSON class. If holder is a global variable, you can get its reference by calling IHTMLDocument::Script.

I am not sure whether Type.InvokeMember would work on a JSON object since the methods are added at runtime, try query IDispatchEx interface from the object to call the methods.

Sheng Jiang 蒋晟