我有一个active-x类是用c#编写的,它是多线程的.我需要从我的activeX调用javascript。我是用Microsoft.mshtml做的。
/*JS
function do_Print() {
control.setPage(this);
control.scriptPrint();
}
function report_back(report){
alert("Report:"+report);
}
C#
public void setPage(mshtml.HTMLWindow2Class JSFile) {
window = JSFile;
}
public void scriptPrint(){
window.execScript("report_back('Printing complete!')", "JScript");
}
*/但它的抛出异常
“无法将'mshtml.HTMLWindow2Class‘类型的COM对象转换为接口类型'mshtml.DispHTMLWindow2'”
还有别的方法吗。我能够从java脚本调用active-x函数,但反之亦然。对多线程c# active-x调用javascript函数有什么想法吗?
发布于 2012-05-31 12:43:32
您可以像这样访问html
private void MyControl_Load(object sender, EventArgs e)
{
if (this.Site != null)
{
htmldoc = (HtmlDocument)this.Site.GetService(typeof(HtmlDocument));
}
}然后在任意按钮上单击我们的C#控件调用方法来单击html按钮。
HtmlElement setCLIButton = htmldoc.GetElementById("searchButton");
setCLIButton.InvokeMember("onClick");通过这种方式,您可以调用javacsript函数,希望它能帮助到某人。
https://stackoverflow.com/questions/2296492
复制相似问题