webbrowser禁止弹出新窗口
让webbrowser弹出新窗口在原来的webbrowser里显示,不弹出IE,不重新打开一个form显示,应该如何设置?
Private Sub Web1_NewWindow2(ppDisp As Object, Cancel As Boolean)
On Error Resume Next
Set ppDisp = Web1.Object '在本窗体中打开新网面,可能会导致出错。
End Sub
----------------我使用的代码是:----------------------
Private Sub Web1_NewWindow2(ppDisp As Object, Cancel As Boolean)
On Error Resume Next
Set ppDisp = WebBrowser2.Object '在另一个窗体中打开。
End Sub
'当在第二个窗体要打开数据时,就转第一个窗体打开
Private Sub WebBrowser2_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
On Error Resume Next
If Not 导航转窗口 Then '如果没有转窗口,就直接转窗口
If Len(PostData) > 0 Then
'有 POST 数据
导航转窗口 = True
Else
Cancel = True
Web1.Navigate URL
End If
End If
End Sub
'转向失败时,再转一次
Private Sub WebBrowser2_DocumentComplete(ByVal pDisp As Object, URL As Variant)
'
If InStr(1, URL, gamehomeurl) > 0 Then
Web1.Navigate URL
'WebBrowser2.Navigate "about:blank"
导航转窗口 = False
End If
End Sub