![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
public 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
{
}
}
使用时: SetAllWebItemSelf(this.webBrowser1.Document.All);