日期:2014-05-18 浏览次数:21186 次
private void webBrowser_NewWindow(object sender, CancelEventArgs e)
        {
            Form1 newForm = new Form1();
            string url = ((WebBrowser)sender).StatusText;
            //string url = ((WebBrowser)sender).Document.ActiveElement.GetAttribute("href");第二种方式
            newForm.webBrowser1.Navigate(url) ;
            newForm.show();
            e.Cancel = true;
        }
------解决方案--------------------
HtmlElementCollection hc = this.webBrow.Document.Links;
           foreach (HtmlElement he in hc)
           {
               if (he.GetAttribute("href").Contains(""))
               {
                   he.SetAttribute("", "");
               }
           }
WebBrowser控件弹出新窗体
------解决方案--------------------
/// <summary>
        /// 查找连接
        /// </summary>
        /// <param name="dcoument"></param>
        /// <returns></returns>
        public static string FindHref(HtmlDocument dcoument)
        {
            string href = null;
            var el = dcoument.ActiveElement;
            if (el.TagName.IndexOf("frame", StringComparison.CurrentCultureIgnoreCase) > -1)
            {
                if (!string.IsNullOrEmpty(el.Id))
                {
                    var frame = dcoument.Window.Frames[el.Id];
                    href = FindHref(frame.Document);
                }
            }
            else
            {
                href = el.GetAttribute("href");
                if (string.IsNullOrEmpty(href) ||
                    href.IndexOf("http://", StringComparison.CurrentCultureIgnoreCase) < 0)
                {
                    href = null;
                }
            }
            return href;
        }
------解决方案--------------------
你点击我前面的留言,我们用QQ说。
感谢你一直以来的支持,欢迎使用《Csdn收音机》!
------解决方案--------------------
------解决方案--------------------
试试Navigate(String, Boolean)的重载形式,第二个参数为true,则导航的页面将使用新窗口打开,效果和右键点击新窗口打开一样,只不过还是用webbrowser显示。