当前位置:编程学习 > C#/ASP.NET >>

winform访问网页中的javascript,就这些分了。。。帮忙啊

小弟最近用vs 2003 开发的client端程序,用到了ActiveX web browser 控件,里面用需要调用在服务器端页面中的javascript函数。有个问题,在xp的一些机器上,这端程序跑不起来,原因是microsoft.mshtml.dll的版本(似乎是7.0.0.3)有些老版本os似乎不兼容,结果不可用,您可能也看到了,我试图用动态编译引用执行,去自动引用客户端适当的mshtml版本,但是还是不行。很急啊,帮忙
各位给个建议吧~可否有其他方案(譬如用ieframe操作IE? 或者我可否在静默状态打开IE去执行页面脚本?不打开IE窗口),我自己可以控制这个服务器端的页面的,目前就写了一个html页面,嵌入javascript而已。另外我试了用httprequest得到页面脚本,再用DOM在客户端执行页面脚本,但是由于要检查安全性,所以在客户端执行不行。。。老师帮忙~~~

代码:

Type htmlDocEngine = obj.GetType();

System.Reflection.PropertyInfo[] perInfos = htmlDocEngine.GetProperties();
System.Reflection.PropertyInfo perInfo = htmlDocEngine.GetProperty("Script");

if(perInfo==null){MessageBox.Show("111 is null");}
// mshtml.IHTMLDocument2 Doc = (mshtml.IHTMLDocument2)this.axwb_exe.Document;//就是这个IHTMLDocument2不识别
//
// Type ScriptEng = Doc.Script.GetType();
object obj_script = new object();
obj_script=perInfo.GetValue(obj,null);

Type ScriptEng = obj_script.GetType();//GetType();

try
{
oReturn = ScriptEng.InvokeMember(sFunction, System.Reflection.BindingFlags.InvokeMethod, null, obj_script, oParameters);
}
catch (Exception ex)
{
MessageBox.Show("Error invoking function: " + ex.Message, "InvokeScript - Exception", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
return oReturn;

--------------------编程问答-------------------- up --------------------编程问答-------------------- In your project, change copylocal property of microsoft.mshtml.dll from false to true. Put a copy of the dll in your install directory. 

Note on maintaining compatibility across multiple versions
If you compile your project with IE7 type libraries, be aware your project may not work on IE6. You are using IE components that you do not redistribute with your setup package, and you cannot be assured of the exact version you will be communicating with at run-time, you should pay special attention to early bind to an interface that is compatible with all versions of the component, or (in some cases) use late binding to call a method that may exist in a particular version and fail gracefully if that method is not present in the version installed on the client system.

Because mshtml is an unmanaged COM component that allows only full-trusted callers, you will need Full Trust code access permissions to run the code (http://support.microsoft.com/kb/311295) --------------------编程问答-------------------- 哎,蒋晟老大帮我看看这个问题吧,CSDN发短消息发不出去

http://community.csdn.net/Expert/topic/5682/5682940.xml?temp=.9618189

都搞了一星期了,谢谢~
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,