使用 WebBrowser 操作 js

winForm下的WebBrowser控件可以执行当前页面已存在的js,但不支持自定义js操作。

 

因此要使用引用Microsoft.mshtml.dll来实现。

 

该dll里面的接口各负责不同的工作。

mshtml.IHTMLWindow2  可负责js操作。

   mshtml.IHTMLDocument2 currentDoc = (mshtml.IHTMLDocument2)webBrowser1.Document.DomDocument;
                mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2)currentDoc.parentWindow;
               win.execScript("F1('日本')", "javascript");//调用函数F1

posted on 2011-11-09 18:02  飞舞的蒲公英  阅读(906)  评论(0编辑  收藏  举报