Q:winform中如何實現自動點擊webbrowser彈出對話框中的確定按鈕
A:
//using msHtml;
//using SHDocVw;
private void Form1_Load(object sender, EventArgs e)
...{
this.webBrowser1.Navigate("http://localhost:28512/WebSite2/Default.ASPx");
SHDocVw.WebBrowser wb = this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser;
wb.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(wb_NavigateComplete2);
}
void wb_NavigateComplete2(object pDisp, ref object URL)
...{
mshtml.IHTMLDocument2 doc = (this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).Document as mshtml.IHtmlDocument2;
doc.parentWindow.execScript("function alert(str){return ''''}", "Javascript");
}