简体   繁体   English

webbrowser检测链接单击并在新窗口中打开vb.net

[英]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. 我当前在连接浏览器中的链接时打开新窗口时遇到问题,我无法使用webbrowser.Navigating,因为在用户可以访问该链接以打开新窗口之前已经进行了多种导航。 I've already looked at vb.net Detect if a link is clicked in Webbrowser control but that didn't help very much. 我已经看过vb.net检测Webbrowser控件中是否单击了链接,但这并没有太大帮助。 Is there a way to detect a linkclick in a webbrowser? 有没有办法检测Web浏览器中的linkclick? I'm at a loss right now an will appreciate any help. 我现在很茫然,不胜感激。

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

I would try this link, which in turn was linked from this other post. 我会尝试链接,而链接又是从其他帖子链接的。 Both of which are using C#, however, you can convert it here if it fits your needs. 两者都使用C#,但是,如果需要,可以在此处转换。

Essentially adding an event to the WebBrowser Document. 本质上是将事件添加到WebBrowser文档中。

However, if you do this, it can be fussy. 但是,如果这样做,可能会很麻烦。 At times it can trigger twice if not coded perfectly. 如果编码不正确,有时可能会触发两次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM