0
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.

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by Oxiegen
0

Do some string manipulation and look for the attribute "target" and/or "onclick=javascript:window.open". If found, remove them from the url string before navigating.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.