在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”);
}
本文介绍了一种在Winform应用中使用webbrowser控件时屏蔽或自动处理弹出对话框的方法,通过设置JavaScript行为来禁用alert、confirm等窗口。
2727

被折叠的 条评论
为什么被折叠?



