在Winform编写的基于webbrowser控件的有事会遇到弹出对话框,比如载入一个新网站的时候,原来的网站要求确认是否离开,如何屏蔽或自动点击弹出对话框中的确定按钮,最简单的办法是:引入using mshtml;
private void goToolStripMenuItem_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
webBrowser1.Navigate(url1,null,null,null);
IHTMLWindow2 win = (IHTMLWindow2)webBrowser1.Document.Window.DomWindow;
string s = “window.alert = null;/r/nwindow.confirm = null;/r/nwindow.open = null;/r/nwindow.showModalDialog = null;”;
win.execScript(s, “javascript”);
}