webbowser 弹出新窗口固定在本窗口的方法

控件 webbowser 在使用过程中,当网页需要弹出新窗口的时候 往往会打开IE浏览器,但是有时候想固定在本窗口 不想打开新的IE窗口,这需要使用如下方法

   (this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).NewWindow3 += (new DWebBrowserEvents2_NewWindow3EventHandler(this.Form1_NewWindow));
            //(this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).Silent = true;

       private void Form1_NewWindow(ref object ppDisp, ref bool Cancel, uint dwFlags, string UrlContext, string Url)
        {
         
                this.webBrowser1.Navigate(Url);
                Cancel = true;
            }
        }

添加这个事件,并在事件中处理即可。

原文地址:https://www.cnblogs.com/liaoyi/p/9016209.html