none
VB.NET 如何让 WebBrowser1 弹出新窗口在 WebBrowser2中? RRS feed

答案

  • 你好:

    可以尝试监视鼠标点击事件,鼠标点击之后获取到点击的超链接的URL,然后在第二个webbrowser中打开该链接:

    Public Class Form1
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Me.WebBrowser1.Navigate("http://www.microsoft.com")
    
            AddHandler Me.WebBrowser1.DocumentCompleted, AddressOf browser_DocumentCompleted
    
        End Sub
    
        Private Sub browser_DocumentCompleted(sender As [Object], e As WebBrowserDocumentCompletedEventArgs)
    
            AddHandler Me.WebBrowser1.Document.Body.MouseDown, AddressOf body_MouseDown
        End Sub
    
        Private Sub body_MouseDown(sender As [Object], e As HtmlElementEventArgs)
            If e.MouseButtonsPressed = System.Windows.Forms.MouseButtons.Left Then
                Dim element As HtmlElement = Me.webBrowser1.Document.GetElementFromPoint(e.ClientMousePosition)
                Dim url As String = element.GetAttribute("href")
                Me.webBrowser2.Navigate(url)
            End If
    
        End Sub
    
    End Class

    或者通过WebBrowser.Navigating事件来捕获跳转的连接URL,通过NavigatingEventArgs参数来获取URL值并且取消跳转。


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2015年4月22日 5:41
    版主