How to execute javascript using the mshtml

6.4k Views Asked by At
mshtml.HTMLDocumentClass doc = (mshtml.HTMLDocumentClass)IE.Document;
object script= doc.Script;
object[] args = { FirstArgument , "FrameContent", "tree.aspx", "FrameNav" };
script.GetType().InvokeMember("ZweiFrames", 
                              System.Reflection.BindingFlags.InvokeMethod, 
                              null, script,args);
Marshal.ReleaseComObject(script);

I used the above code to execute java script and getting an error.(Exception has been thrown by the target of an invocation) ( inner Exception : Insufficient memory to continue the execution of the program).

Please help me on this..

Thanks in advance.. Unni.

1

There are 1 best solutions below

0
On

Have you checked ZweiFrames js function - may be there is issue in that function with arguments supplied by you?

BTW, yet another way to execute javascript function can be something like

HTMLWindow2 iHtmlWindow2 = (HTMLWindow2) doc.Script ;
iHtmlWindow2.execScript( "functionName(param1);" , "javascript" );

This is of course assuming that your parameters can be represented in a string form.