[C#] 纯文本查看 复制代码
Type type = Type.GetTypeFromProgID("ScriptControl");//获取脚本对象
object obj = Activator.CreateInstance(type);//Type
type.InvokeMember("Language", BindingFlags.SetProperty, null, obj, new object[] { "JScript" }); //设置语言类型
string resultStr = "";
try
{
type.InvokeMember("AddCode", BindingFlags.InvokeMethod, null, obj, new object[] {"function aa(){return document;}"});//添加JS代码 strJs.Replace("window","this")
resultStr = type.InvokeMember("Eval", BindingFlags.InvokeMethod, null, obj, new object[] { "aa();"}).ToString();//执行JS
}
catch (TargetInvocationException targetEx)
{
if (targetEx.InnerException != null)
{
throw targetEx.InnerException;
}
}
提示document未定义,怎么获取document,又怎么添加到成员里
|