WebBrowser 错误处理
一般来说,将WebBrowser控件ScriptErrorsSuppressed 设置为True,可禁止弹出脚本错误对话框,ScriptErrorsSuppressed属性是对其基础COM控件的Silent属性的封装,因此设置ScriptErrorsSuppressed属性和设置其基础COM控件的Slient属性是效果一样的,这一点通过反编译System.Windows.Forms程序集可以证实。
不过要注意的是:
ScriptErrorsSuppressed 设置为True会禁用所有的对话框,比如提示Activex下载、执行以及安全登录等对话框。
View Code
不过要注意的是:
ScriptErrorsSuppressed 设置为True会禁用所有的对话框,比如提示Activex下载、执行以及安全登录等对话框。
如果不想禁止除脚本错误之外的对话框,请使用MSDN上的代码示例:
View Code
private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
((WebBrowser)sender).Document.Window.Error += new HtmlElementErrorEventHandler(Window_Error);
}
private void Window_Error(object sender, HtmlElementErrorEventArgs e)
{
// Ignore the error and suppress the error dialog box.
e.Handled = true;
{
((WebBrowser)sender).Document.Window.Error += new HtmlElementErrorEventHandler(Window_Error);
}
private void Window_Error(object sender, HtmlElementErrorEventArgs e)
{
// Ignore the error and suppress the error dialog box.
e.Handled = true;
作者:一修先生
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。


浙公网安备 33010602011771号