VB.Net-如何在GeckoFX60中获取新窗口URL

时间:2019-06-19 17:50:42

标签: vb.net geckofx

如何从GeckoFX60中新打开的窗口中获取网址

C#代码:

Private Sub GeckoWebBrowser1_CreateWindow(sender As Object, e As Gecko.GeckoCreateWindowEventArgs) Handles GeckoWebBrowser1.CreateWindow
    Try
        e.Cancel = True
        Console.WriteLine(e.WebBrowser.Url.AbsoluteUri)

    Catch ex As Exception

    End Try
End Sub

但是我在vb.net中找不到e.Uri

我尝试了e.WebBrowser.Url.AbsoluteUri,但它始终为空

这就是我在vb.net中尝试过的

ln -s

1 个答案:

答案 0 :(得分:0)

在GeckoWebBrowser的CreateWindow事件的GeckoFX 60.x中,Uri GeckoCreateWindowEventArgs对象上没有e属性。

要获取URL,请创建一个新的GeckoBrowser实例,然后在导航事件中获取URL

Here's来自GeckoFX论坛上相关线程的一些示例代码:

Private Sub Gecko_CreateWindow(sender As Object, e As GeckoCreateWindowEventArgs) Handles Gecko.CreateWindow
    'Create new form & initialise the browser
    Dim Frm As New GeckoFrm
    Dim h = Frm.Gecko.Handle

    'Keep flags for use in Navigating event
    If e.Flags = GeckoWindowFlags.All Then
        Frm.Gecko.SetContextFlagsAttribute(ContextFlags.Tab)
    Else
        Frm.Gecko.SetContextFlagsAttribute(ContextFlags.Popup)
    End If

    'Pass back the browser
    e.WebBrowser = Frm.Gecko
End Sub

Private Sub Gecko_Navigating(sender As Object, e As GeckoNavigatingEventArgs) Handles Gecko.Navigating
    If Gecko.GetContextFlagsAttribute And ContextFlags.Tab Then
        'Navigate existing or open tab
        NavigateTab(e.Uri.ToString)
    ElseIf Gecko.GetContextFlagsAttribute And ContextFlags.Popup Then
        If BlockPopup()
            e.Cancel = True
            Return
        Else
            'navigate existing or open popup
            NavigatePopup(e.Uri.ToString)
        End If
    Else
        'Not a popup, just show 
        Show()
    End If
    'Clear the popup/tab flags
    Gecko.SetContextFlagsAttribute(0)
End Sub