Search code examples
vb.nethyperlinkclickwindowdetect

webbrowser detect link click and open in new window vb.net


I currently am having a problem having a new window open when a link is clinked in my webbrowser, I cannot use webbrowser.Navigating because there are several navigations already occurring before a user can get to the link to open the new window. I've already looked at vb.net Detect if a link is clicked in Webbrowser control but that didn't help very much. Is there a way to detect a linkclick in a webbrowser? I'm at a loss right now an will appreciate any help.


Solution

  • I was able to figure out how to do it, the code is below for anyone that has a similar problem.

    Private Sub webMailNavigating(sender As Object, e As WebBrowserNavigatingEventArgs) Handles webMail.Navigating
    
        ' opens link in new tab if it isn't blank and will not open emails in a new tab.
        Try
            If Not e.Url.ToString.Contains("emailUrl") And Not e.Url.ToString.Contains("about:blank") Then
                e.Cancel = True
                Process.Start(e.Url.ToString)
    
            Else
    
            End If
    
        Catch
    
        End Try
    End Sub