WebBrowser.ScriptErrorsSuppressed プロパティ

定義

WebBrowser がスクリプト エラー メッセージなどのダイアログ ボックスを表示するかどうかを示す値を取得または設定します。

public:
 property bool ScriptErrorsSuppressed { bool get(); void set(bool value); };
public bool ScriptErrorsSuppressed { get; set; }
member this.ScriptErrorsSuppressed : bool with get, set
Public Property ScriptErrorsSuppressed As Boolean

プロパティ値

コントロールがそのダイアログ ボックスを表示しない場合は true。それ以外の場合は false。 既定値は、false です。

例外

この WebBrowser インスタンスは無効になっています。

IWebBrowser2 インターフェイスの実装への参照を、基になる ActiveX WebBrowser コントロール から取得できませんでした。

次のコード例では、他のダイアログ ボックスを抑制せずにスクリプト エラーを抑制する方法を示します。 この例では、 プロパティが にfalse設定され、ScriptErrorsSuppressedダイアログ ボックスが確実に表示されます。 イベントのハンドラーは HtmlWindow.Error エラーを抑制します。 このイベントは、ドキュメントの読み込みが完了したときにのみアクセスできるため、ハンドラーはイベント ハンドラーに DocumentCompleted アタッチされます。

// Hides script errors without hiding other dialog boxes.
private void SuppressScriptErrorsOnly(WebBrowser browser)
{
    // Ensure that ScriptErrorsSuppressed is set to false.
    browser.ScriptErrorsSuppressed = false;

    // Handle DocumentCompleted to gain access to the Document object.
    browser.DocumentCompleted +=
        new WebBrowserDocumentCompletedEventHandler(
            browser_DocumentCompleted);
}

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;
}
' Hides script errors without hiding other dialog boxes.
Private Sub SuppressScriptErrorsOnly(ByVal browser As WebBrowser)

    ' Ensure that ScriptErrorsSuppressed is set to false.
    browser.ScriptErrorsSuppressed = False

    ' Handle DocumentCompleted to gain access to the Document object.
    AddHandler browser.DocumentCompleted, _
        AddressOf browser_DocumentCompleted

End Sub

Private Sub browser_DocumentCompleted(ByVal sender As Object, _
ByVal e As WebBrowserDocumentCompletedEventArgs)

    AddHandler CType(sender, WebBrowser).Document.Window.Error, _
        AddressOf Window_Error

End Sub

Private Sub Window_Error(ByVal sender As Object, _
    ByVal e As HtmlElementErrorEventArgs)

    ' Ignore the error and suppress the error dialog box. 
    e.Handled = True

End Sub

注釈

コントロールに false 表示する Web ページをデバッグするには、このプロパティを WebBrowser に設定します。 これは、 コントロールを使用して Web ベースのコントロールとスクリプト コードをアプリケーションに追加する場合に便利です。 コントロールを汎用ブラウザーとして使用する場合は、あまり役に立ちません。 アプリケーションのデバッグが完了したら、スクリプト エラーを抑制するには、このプロパティを に true 設定します。

注意

が にtrue設定されている場合ScriptErrorsSuppressed、コントロールはWebBrowser、スクリプト エラーだけでなく、基になる ActiveX コントロールから生成されたすべてのダイアログ ボックスを非表示にします。 場合によっては、ブラウザーのセキュリティ設定やユーザー ログインに使用されるダイアログ ボックスなどのダイアログ ボックスを表示するときに、スクリプト エラーを抑制することが必要になる場合があります。 この場合、 を にfalse設定ScriptErrorsSuppressedし、イベントのハンドラーでスクリプト エラーを抑制しますHtmlWindow.Error。 詳細については、このトピックのコード例を参照してください。

適用対象

こちらもご覧ください