1
我檢查了其他線程,但沒有爲我工作。 他們之後,我實現了到目前爲止是這樣的:在網頁瀏覽器中阻止自定義廣告對話框
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;
}
網站我想取消的網址如下: 警告類似騙局 http://cdn.adbooth.net/src/autoshortner.html?section=3605070&url=url_i_want_goes_here.com