如果你有使用webbrowser,那你一定遇到了这个问题。
针对WebBrowser控件中自动点击弹出框及禁用脚本提示问题
有时候我们在这一问题上,并不是固定哪一种方法可用,因此对于遇到过的问题进行整理了下
方法一:通过设置Webbrowser的属性来实现
将WebBrowser控件ScriptErrorsSuppressed设置为True即可

方法二:通过控制webbrowser加载后就点击掉,以达到效果
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) {
IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;
vDocument.parentWindow.execScript("function confirm(str){return true;} ", "javascript");
vDocument.parentWindow.execScript("function alert(str){return true;} ", "javaScript");
}
方法三:在页面加载完成后自动关闭,与方法二大体相同
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e){
IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;
vDocument.parentWindow.execScript("function confirm(str){return true;} ", "javascript");
vDocument.parentWindow.execScript("function alert(str){return true;} ", "javaScript");
}