如何判断webbrowser中当用户点击右键选择 打开新窗口 或是网页上的 脚本控制打开一个新窗口的时候,捕获这个要打开的新窗口的网址。并且禁止打开新窗口呢。

解决方案 »

  1.   

    Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
    MsgBox "OK"
    Cancel = True
    End Sub
      

  2.   

    Private WithEvents newIe As InternetExplorer
    Private WithEvents newIewin As ShellWindows
    Dim isnew As BooleanPrivate Sub Command1_Click()
    Set newIewin = New ShellWindows
    WebBrowser1.Navigate "http://office.9zp.com/index.asp"
    End SubPrivate Sub newIe_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    If newIe.LocationURL <> "" Then
    MsgBox newIe.LocationURL
    newIe.Quit
    End If
    End SubPrivate Sub newIewin_WindowRegistered(ByVal lCookie As Long)
    If isnew Then
    Set newIe = newIewin.Item(newIewin.Count - 1)
    End If
    End SubPrivate Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
    isnew = True
    End Sub
      

  3.   

    litaoa(青云)
    要手工引用一下如下这个DLL
    \WINDOWS\SYSTEM\SHDOCVW.DLL
    (我在OFFICE的VBA中试时,WebBrowser直接来自SHDOCVW.DLL,VB6中还是来自SHDOCVW.oca)