.net里的webbrowser,怎么准确获取弹出窗口的网址,并在自己的新窗口中继承打开

   阅读
.net里的webbrowser,如何准确获取弹出窗口的网址,并在自己的新窗口中继承打开。
Private Sub Web1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Web1.NewWindow

  Dim NewURL As String = CType(sender, Windows.Forms.WebBrowser).StatusText
  Dim myfrm As New FormWeb

  e.Cancel = True
  myfrm.Show()
  myfrm.Web1.Navigate(NewURL)
  End Sub

这段代码是我之前用的,对于普通文字链接是可以正确弹出网页,但对于网页内用按钮弹出,或是javascript弹出的,就无法获取正确的弹出网址。或者说是没有继承性,若是防盗链的网站用navigate直接打开新网址估计也会出错。
请问还有什么更规范的写法或办法可以解决这问题,实现类似于一些腾讯TT第三方的浏览器。

注意,我用的是.net里自带的那个Webbrowser,而不是以前6.0里那个axWebbrowser,它俩提供的方法完全不同。后者好象是可以用ppdisp实现,但我希望得到前者的解答。望指教!

------解决方案--------------------
好久没做过Web了,忘了,帮顶一下,学习学习
------解决方案--------------------
利用网页元素
ELE开头的
------解决方案--------------------
WebBrowser1.Document.Url

------解决方案--------------------
对于这个问题我也一直很困惑,我也很想知道解决方案。帮你顶了

------解决方案--------------------
我的做法并不正统.我是通过监视状态栏来取得的:

VB.NET code
Namespace LzmTW.uSystem.uWindows.uForms.Web
    <Docking(DockingBehavior.AutoDock), Designer("System.Windows.Forms.Design.WebBrowserDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ClassInterface(ClassInterfaceType.AutoDispatch), DefaultEvent("DocumentCompleted"), ComVisible(True), DefaultProperty("Url")> _
    <System.Drawing.ToolboxBitmap(GetType(System.Windows.Forms.WebBrowser))> _
    Public Class WebBrowserEx
        Inherits System.Windows.Forms.WebBrowser

        Friend Const DefaultUri As String = "about:blank"
        Private WithEvents gComInternetExplorer As SHDocVw.InternetExplorer
        Private gCanNewWindow As Boolean = True

        Public Property CanNewWindow() As Boolean
            Get
                Return Me.gCanNewWindow
            End Get
            Set(ByVal value As Boolean)
                Me.gCanNewWindow = value
            End Set
        End Property


        Sub New()
            Me.Url = New System.Uri(DefaultUri, System.UriKind.Absolute)
        End Sub

        Private Sub WebBrowser_HandleCreated(ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles Me.HandleCreated
            Me.gComInternetExplorer = CType(Me.ActiveXInstance, SHDocVw.InternetExplorer)
            With gStatusList
                .Add(SHDocVw.OLECMDID.OLECMDID_CUT, False)
                .Add(SHDocVw.OLECMDID.OLECMDID_COPY, False)
                .Add(SHDocVw.OLECMDID.OLECMDID_PASTE, False)
            End With

        End Sub

        ''按钮、状态栏的隐藏显示
        ''动作由菜单发出

        Public Event StatusBarVisibleChanged As EventHandler
        Public Event AddressBarVisibleChanged As EventHandler
        Public Event LinkBarVisibleChanged As EventHandler
        Public Event StandarBarVisibleChanged As EventHandler

        Private gStatusBarVisible As Boolean
        Private gAddressBarVisible As Boolean
        Private gLinkBarVisible As Boolean
        Private gStandarBarVisible As Boolean

        Public Property StatusBarVisible() As Boolean
            Get
                Return Me.gStatusBarVisible
            End Get
            Set(ByVal value As Boolean)
                If Me.gStatusBarVisible <> value Then
                    Me.gStatusBarVisible = value
                    RaiseEvent StatusBarVisibleChanged(Me, New EventArgs)
                End If
            End Set
        End Property

        Public Property AddressBarVisible() As Boolean
            Get
                Return Me.gAddressBarVisible
            End Get
            Set(ByVal value As Boolean)
                If Me.gAddressBarVisible <> value Then
                    Me.gAddressBarVisible = value
                    RaiseEvent AddressBarVisibleChanged(Me, New EventArgs)
                End If
            End Set
        End Property

        Public Property LinkBarVisible() As Boolean
            Get
                Return Me.gLinkBarVisible
            End Get
            Set(ByVal value As Boolean)
                If Me.gLinkBarVisible <> value Then
                    Me.gLinkBarVisible = value
                    RaiseEvent LinkBarVisibleChanged(Me, New EventArgs)
                End If
            End Set
        End Property

        Public Property StandarBarVisible() As Boolean
            Get
                Return Me.gStandarBarVisible
            End Get
            Set(ByVal value As Boolean)
                If Me.gStandarBarVisible <> value Then
                    Me.gStandarBarVisible = value
                    RaiseEvent StandarBarVisibleChanged(Me, New EventArgs)
                End If
            End Set
        End Property

        ''New Window
        Private gNewWindowUri As Uri = New Uri(DefaultUri)
        Public ReadOnly Property NewWindowUri() As Uri
            Get
                Return gNewWindowUri
            End Get
        End Property

        Protected Overrides Sub OnStatusTextChanged(ByVal e As System.EventArgs)
            If UrlHelper.Common.IsValidURL(Me.StatusText) Then
                gNewWindowUri = New Uri(Me.StatusText)
            End If

            MyBase.OnStatusTextChanged(e)
        End Sub

        Protected Overrides Sub OnNewWindow(ByVal e As System.ComponentModel.CancelEventArgs)
            Dim mElement As HtmlElement = Me.Document.ActiveElement
            Dim mHref As String = mElement.GetAttribute("href")
            If Not String.IsNullOrEmpty(mHref) Then
                gNewWindowUri = New Uri(mHref)
            End If

            If Not Me.CanNewWindow Then
                e.Cancel = True
                Me.Navigate(Me.NewWindowUri)
            Else
                MyBase.OnNewWindow(e)
            End If
        End Sub
    End Class
End Namespace

阅读