我在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中。
答案 0 :(得分:0)
WebBrowser1.Document.ActiveElement
正在返回Nothing
,因为没有有效元素。因此,当您尝试使用targeturl
时,会出现此错误:Object reference not set to an instant of object
答案 1 :(得分: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