The same code, I tried many times did not succeed. Finally succeeded because I didn't call this code in the right event .
Private voidInjectalertblocker () {htmlelement head= WbNav.Document.GetElementsByTagName ("Head")[0]; HtmlElement Scriptel= WbNav.Document.CreateElement ("Script"); Mshtml. IHTMLScriptElement element=(MSHTML. IHTMLScriptElement) scriptel.domelement; stringAlertblocker ="Window.alert = function () {}"; Element.text=Alertblocker; Head. AppendChild (Scriptel); Wbnav.scripterrorssuppressed=true; }
// prevent new Windows from popping up Private void Wbnav_newwindow (object sender, CancelEventArgs e) { true; } //must be called in this event to be disabled, previously written in other events, wasted 2 hours. Private void wbnav_navigated (object sender, WebBrowserNavigatedEventArgs e) { injectalertblocker (); }
In order to deepen the impression, special record.
BTW, don't forget to add Mshtml.dll this component. Full Name: Microsoft HTML Object Library
C # WebBrowser controls disable pop-up solutions like alert,confirm