2013-03-26 65 views
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

回答

0

我做了一個patc h /修復解決方案在兩個步驟...位哈克...

檢查網址,如果它被重定向,我們得到的下一個網址,等等adbooth字符串。 (How to programatically lengthen shortened urls

然後在導航事件(只是要確定)和導航之前,在情況下,我可以,我喜歡修剪網址:

private string noAdBooth(string lnk) 
    { 
     if (lnk.Contains("&url=") && lnk.Contains("adbooth")) 
     { 
      añadeTextoDebug("adbooth omitted"); //add txt debug 
      lnk = lnk.Substring(lnk.IndexOf("&url=") + 5); 
     } 
     return lnk; 
    }