关注联楷|返回首页 | 网站案例 | 帮助中心

合作共赢、快速高效、优质的网站建设提供商

上海网站建设 

服务热线:021-61394118

上海联楷科技

C# WebBrowser强制使新窗口网页只在WebBrowser打开

作者:佚名   时间:2012-05-01   分享到:

private void wB_MainBrowser_NewWindow(object sender, CancelEventArgs e)
         {
             e.Cancel = true;
             try
             {
                 string url = this.wB_MainBrowser.Document.ActiveElement.GetAttribute("href");
 
                 this.wB_MainBrowser.Url = new Uri(url);
             }
             catch
             {
             }
         }




private void SetAllWebItemSelf(HtmlElementCollection items)
         {
             try
             {
                 foreach (HtmlElement item in items)
                 {
                     if (item.TagName.ToLower().Equals("iframe", StringComparison.OrdinalIgnoreCase)==false)
                     {
                         try
                         {
                             item.SetAttribute("target", "_self");
                         }
                         catch
                         { }
                     }
                     else
                     {
                         try
                         {
                             HtmlElementCollection fitems = item.Document.Window.Frames[item.Name].Document.All;
 
                             this.SetAllWebItemSelf(fitems);
                         }
                         catch
                         { }
                     }
                 }
             }
             catch
             {
             }
         }



如没特殊注明,文章均为上海联楷网络原创,转载请注明来自:http://www.linksj.com/contact/20151229/n7590.html

上海联楷网络新闻