/// <summary>
/// 完成加载事件
/// </summary>
private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//将所有的链接的target改为_self
foreach (HtmlElement anchor in this.webBrowser1.Document.Links)
{
anchor.SetAttribute("target", "_self");
}
//将所有的FORM的target改为_self
foreach (HtmlElement form in this.webBrowser1.Document.Forms)
{
form.SetAttribute("target", "_self");
}
}
/// 完成加载事件
/// </summary>
private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//将所有的链接的target改为_self
foreach (HtmlElement anchor in this.webBrowser1.Document.Links)
{
anchor.SetAttribute("target", "_self");
}
//将所有的FORM的target改为_self
foreach (HtmlElement form in this.webBrowser1.Document.Forms)
{
form.SetAttribute("target", "_self");
}
}
2. 新窗口事件中禁止打开新窗口
/// <summary>
/// 新窗口事件
/// </summary>
private void webBrowser1_NewWindow(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}
/// 新窗口事件
/// </summary>
private void webBrowser1_NewWindow(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}