將WebBrowser控件ScriptErrorsSuppressed
設置為True,可禁止彈出腳本錯誤對話框,ScriptErrorsSuppressed屬性是對其基礎COM控件的Silent屬性的封裝,因此設置ScriptErrorsSuppressed屬性和設置其基礎COM控件的Slient屬性是效果一樣的,這一點通過反編譯System.Windows.Forms程序集可以證實。
為了解決這個問題,有的人專門從WebBrowser派生出一個新類,然后重寫了AttachInterfaces方法,其實也是沒有必要的,效果和直接設置ScriptErrorsSuppressed屬性相同。
不過要注意的是:
ScriptErrorsSuppressed 設置為True會禁用所有的對話框,比如提示Activex下載、執行以及安全登錄等對話框。
如果不想禁止除腳本錯誤之外的對話框,請使用MSDN上的代碼示例:
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;
}
