开发者

How to disable Alert box javascript in c# webbrower control?

When I navigate some website using We开发者_JS百科bBrower control but it show alert box from java script page's how to disable its?


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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜