When I navigate some website using WebBrower control but it show alert box from java script page's how to disable its?
            Asked
            
        
        
            Active
            
        
            Viewed 8,085 times
        
    2
            
            
         
    
    
        Evgeny Lazin
        
- 9,193
- 6
- 47
- 83
 
    
    
        monkey_boys
        
- 7,108
- 22
- 58
- 82
2 Answers
3
            
            
        You can use the following code for this:
        HtmlElement head = myWebBrowser.Document.GetElementsByTagName("head")[0];
        HtmlElement scriptEl = myWebBrowser.Document.CreateElement("script");
        IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
        string alertBlocker = @"window.alert = function () { };";
        element.text = alertBlocker;
        head.AppendChild(scriptEl);
        myWebBrowser.ScriptErrorsSuppressed = true;
the source took from : http://moshez.blogspot.co.il/2013/08/c-disable-alert-box-javascript-in-c.html
 
    
    
        Moshe Zino
        
- 311
- 1
- 4
2
            
            
        I'm not sure if it's possible, but if you can to inject some code into your control after you get those pages, you can override window.alert function, like:
<script>function window.alert(){ return false; }</script>
<script>
    alert("hi there")  // won't show up
</script>
 
    
    
        Rubens Farias
        
- 57,174
- 8
- 131
- 162