Disabling the notification window in the WebBrowser control

I am using VS 2005 and the WebBrowser control. When I use the component to go to the specified page, I get a script error, for example, "JavaScript script error on this page" and two buttons: yes or no execution script. How to prevent warning windows and continue browsing without these messages?

+4
source share
3 answers

Try

WebBrowser1.ScriptErrorsSuppressed = true; 
+8
source

try it

 HtmlElement head = WebBrowser1.Document.GetElementsByTagName("head")[0]; HtmlElement scriptEl = WebBrowser1.Document.CreateElement("script"); IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement; string alertBlocker = @"window.alert = function () { }; window.confirm=function () { };"; element.text = alertBlocker; head.AppendChild(scriptEl); WebBrowser1.ScriptErrorsSuppressed = true; 

Source: http://moshez.blogspot.co.il/2013/08/c-disable-alert-box-javascript-in-c.html

+3
source
  Private Sub WebBrowser1_StatusTextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser1.StatusTextChanged On Error Resume Next Dim head As HtmlElement = WebBrowser1.Document.GetElementsByTagName("head")(0) Dim script As HtmlElement script = WebBrowser1.Document.CreateElement("script") script.SetAttribute("type", "text/javascript") Dim alertBlocker As String = "window.alert = function () { }; window.confirm=function () { }; " script.SetAttribute("text", alertBlocker) head.AppendChild(script) End Sub 
+1
source

Source: https://habr.com/ru/post/1345664/


All Articles