当我使用WebBrower
控件浏览某些网站时,它从Java脚本页面显示警告框,如何禁用它?
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.