2

When I navigate some website using WebBrower control but it show alert box from java script page's how to disable its?

0

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.