-2

我在href找到了错误,所以请帮助我

Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
    Dim thiselement As HtmlElement = WebBrowser1.Document.ActiveElement
    Dim targeturl As String = thiselement.GetAttribute("href") 
    e.Cancel = True
    Dim window As New Form1
    window.Show()
    window.WebBrowser1.Navigate(targeturl)
End Sub

在“href”处,我发现对象引用未设置为对象瞬间之类的错误。我的代码在 vb.net 2010 中。

4

2 回答 2

0

WebBrowser1.Document.ActiveElement正在返回Nothing,因为没有活动元素。因此,当您尝试使用时targeturl,您会收到此错误:Object reference not set to an instant of object

于 2013-10-01T14:49:22.173 回答
0

处理Navigating事件。例子:

webBrowser1.Navigating += Function(source, args) 
    Dim uriClicked = args.Uri
    ' Create your new form or do whatever you want to do here
End Function
于 2013-10-05T06:25:04.217 回答