Blocking dialogs in .NET WebBrowser control

And for an easy way to inject that magic line of javascript, read how to inject javascript into webbrowser control.

Or just use this complete code:

private void InjectAlertBlocker() {
    HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];
    HtmlElement scriptEl = webBrowser1.Document.CreateElement("script");
    string alertBlocker = "window.alert = function () { }";
    scriptEl.SetAttribute("text", alertBlocker);
    head.AppendChild(scriptEl);
}

Leave a Comment