首页 新闻 会员 周边

C# 执行javascript 怎么获取document

0
[已解决问题] 解决于 2017-07-04 11:59
           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未定义 这个要怎么处理才好

 

atfeel的主页 atfeel | 初学一级 | 园豆:69
提问于:2016-03-26 22:27
< >
分享
最佳答案
0
atfeel | 初学一级 |园豆:69 | 2016-03-31 09:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册