-2

I have found the error at href so please help me

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

at "href" i have found error like Object reference not set to an instant of object. my code is in vb.net 2010.

nathanchere
  • 8,008
  • 15
  • 65
  • 86
Pinal Mishra
  • 5
  • 1
  • 4

2 Answers2

0

WebBrowser1.Document.ActiveElement is returning Nothing because there is no active element. Therefore when you attempt to use targeturl, you get this error: Object reference not set to an instant of object

Steve
  • 5,585
  • 2
  • 18
  • 32
  • @PinalMishra, [this answer](http://stackoverflow.com/a/6473442/1768303) explains how to do exactly what you're asking for, in details. You only need to convert it from C# to VB.NET. Use `ieframe.dll` instead of `shdocvw.dll` to add the reference. – noseratio Oct 02 '13 at 12:51
  • Hey, Does anyone have any idea how can i open new window at click on any dynamic link and my problem platform is vb.net and also remember that new window is not internet explorer window or any other browser – Pinal Mishra Oct 03 '13 at 08:02
0

Handle the Navigating event. Example:

webBrowser1.Navigating += Function(source, args) 
    Dim uriClicked = args.Uri
    ' Create your new form or do whatever you want to do here
End Function
nathanchere
  • 8,008
  • 15
  • 65
  • 86