2013-01-21 75 views

回答

0

您可以使用Document.ActiveElement屬性獲取當前具有用戶輸入焦點的元素。

private void webBrowser1_NewWindow(object sender, CancelEventArgs e) 
{ 
    e.Cancel = true; 

    if (webBrowser1.Document != null) 
    { 
     HtmlElement currentElement = webBrowser1.Document.ActiveElement; 
     if (currentElement != null) 
     { 
      string targetPath = currentElement.GetAttribute("href"); 

      //You can perform some logic here to determine if the targetPath conformsto your specification and if so... 
      MainForm newWindow = new MainForm(); 
      newWindow.webBrowser1.Navigate(targetPath); 
      newWindow.Show(); 

      //Otherwise 
      //webBrowser1.Navigate(targetPath); 

     } 
    } 
} 
相關問題