1

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

我试着放..

MsgBox(e.Url)
e.Cancel = True

在 WebBrowser1_Navigating EVENT 内部,但什么也没做。任何人都可以帮忙吗?

4

2 回答 2

1

您可以尝试为每个链接添加处理程序:

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
于 2013-01-09T10:54:09.837 回答
1

这就是问题所在:

MsgBox(e.Url)

试试这个:

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
于 2013-01-09T17:29:34.830 回答