1

I am trying to develop a plugin to internet explorer browser using csharp and I try to inject a javascript to the loaded page. To inject the javascript i used the following code. The code is injected and the alert is working fine. but code given below should return the value of "msg" to output. when i run this code i get null value for output. kindly help.

var output= HTMLDocument.parentWindow.execScript("msg()","JScript");

function msg(){
    var msg = "This is sample";
    alert(msg);
    return msg;
}
NDM
  • 6,731
  • 3
  • 39
  • 52

2 Answers2

1

According to this page:

https://msdn.microsoft.com/en-us/library/ie/ms536420%28v=vs.85%29.aspx

The execCode method returns some sort of null value. Use eval if you want the value of msg().

jkd
  • 1,045
  • 1
  • 11
  • 27
0

IE cannot eval functions (Presumably for security reasons).

The best workaround is to put the function in an array, like this:

var func = eval('[' + funcStr + ']')