让弹出窗口在自己的浏览器中显示

来源:互联网 发布:神武3手游数据 编辑:程序博客网 时间:2024/05/17 23:27

private void webBrowser1_NewWindow(object sender, CancelEventArgs e)//点击,如果本链接是弹出新窗口,事件就会自动截获。
        {
            try
            {
                string strurl = webBrowser1.Document.ActiveElement.GetAttribute("href");
                if (!strurl.Contains("://"))
                    strurl = "http://" + strurl;
                this.webBrowser1.Url = new System.Uri(strurl, System.UriKind.Absolute);
                e.Cancel = true;
            }
            catch { }
        }
//代码主体意思是,获取截获的Url地址,重新绑定给webbrower浏览器控件,然后把跳转的cancel=true,意思就是不让它弹出IE等默认浏览器。

原创粉丝点击