我检查了其他线程,但对我不起作用。跟随他们,到目前为止我已经实现了这种方式:
private void InjectAlertBlocker()
{
HtmlElement head = webBrowser4.Document.GetElementsByTagName("head")[0];
HtmlElement scriptEl = webBrowser4.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
string alertBlocker = "window.showModalDialog = function () { };";
alertBlocker += "window.alert = function () { };";
alertBlocker += "getUrlParam(strParamName){};";
alertBlocker += "getSpecialUrlsParam(strParamName) {};";
alertBlocker += "closeButton();";
element.text = alertBlocker;
head.AppendChild(scriptEl);
}
从导航和完成的事件中调用 InjectAlertBlocker()。
我也试过:
private void webBrowser_NewWindow(object sender, CancelEventArgs e)
{
WebBrowser wb = sender as WebBrowser;
if (wb != null)
añadeTextoDebug("Un navegador quiso abrir un popup: " + wb.Url);
e.Cancel = true;
}
我想取消的网站网址是这样的:警告 SCAM-LIKE LINK http://cdn.adbooth.net/src/autoshortner.html?section=3605070&url=url_i_want_goes_here.com