2

I have a Webbrowser control on a standard windows form in VB.NET 2005. I just want to detect when someone clicks a link inside the Webbrowser control it just tells me what they clicked on, or where its trying to go, then cancel the process.

I tried putting..

MsgBox(e.Url)
e.Cancel = True

Inside of the WebBrowser1_Navigating EVENT, but that does nothing. Can anyone help?

eqiz
  • 1,521
  • 5
  • 29
  • 51

2 Answers2

1

you could try something like adding a handler for each link:

For Each htmlEle As HtmlElement In Webbrowser1.document.Links
    addhandler htmlElec.click, addressof YourSub
Next

private sub YourSub()
    'do what you want here
end sub
5uperdan
  • 1,481
  • 2
  • 14
  • 30
1

This was the problem:

MsgBox(e.Url)

Try this:

MsgBox(e.Url.ToString())

Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
    If MsgBox("You are trying to go to:" & vbCr & e.Url.ToString() & vbCr & "Cancel Navigate?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
        e.Cancel = True
    End If
End Sub
Logi Guna
  • 218
  • 2
  • 7
  • This works until you click on a link that opens a new window, such as target="_blank" links and download links. – eqiz Jan 10 '13 at 22:37