【问题标题】:Blocking custom ad dialog in webbrowser在网络浏览器中阻止自定义广告对话框
【发布时间】:2013-03-26 20:12:33
【问题描述】:

我检查了其他线程,但不适合我。 跟随他们,到目前为止我已经实现了这种方式:

  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

【问题讨论】:

    标签: javascript .net winforms dialog browser


    【解决方案1】:

    我已经分两步制作了一个补丁/修复解决方案......有点hacky......

    检查 url,如果它被重定向,我们得到的下一个 url 等等以获取 adbooth 字符串。 (How to programatically lengthen shortened urls)

    然后在导航事件(只是为了确定)和导航之前,在我可以的情况下,我将 url 修剪为:

        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;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多