vb.net 检测是否在 Webbrowser 控件中单击了链接

问题描述:

我在 VB.NET 2005 中的标准 Windows 窗体上有一个 Webbrowser 控件.我只想检测何时有人单击 Webbrowser 控件内的链接,它只是告诉我他们单击了什么,或者它试图去哪里,然后取消进程.

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.

我试过把..

MsgBox(e.Url)
e.Cancel = True

在 WebBrowser1_Navigating EVENT 内部,但没有任何作用.有人可以帮忙吗?

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

这就是问题所在:

MsgBox(e.Url)

MsgBox(e.Url)

试试这个:

MsgBox(e.Url.ToString())

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