Private Sub LinkClicked(ByVal sender As Object, ByVal e As EventArgs)
Dim link As HtmlElement = WebBrowser1.Document.ActiveElement
Dim url As String = link.GetAttribute("href")
WebBrowser1.Navigate(url, False)
'MsgBox("Link Clicked: " & link.InnerText & vbCrLf & "Destination: " & url)
End Sub
Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
e.Cancel = True
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
status.Text = WebBrowser1.Url.ToString
status.Refresh()
Dim olink As HtmlElement
Dim olinks As HtmlElementCollection = WebBrowser1.Document.Links
For Each olink In olinks
olink.AttachEventHandler("onclick", AddressOf LinkClicked)
Next
PictureBox2.Visible = True
End Sub
Okay so here's the question how do I get the links that open in a new window to open in my main webbrowser control. The above code does some, but it's not fool proof.