答案 0 :(得分:0)
'
'
Dim MyURL As String
'
'
Private Sub Command1_Click()
MyURL = "http://www.website.com"
WebBrowser1.Navigate2 MyURL
End Sub
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
If Instr(URL, MyURL) > 0 Then
Cancel = True ' Do not allow
End If
End Sub
答案 1 :(得分:0)
这是你要问的一件非常容易的事。看起来像这样。您基本上可以在导航和任何加载之前进入导航事件。然后,您可以检查所需的URL,然后取消导航或重新路由到已批准的网站。
Public Class Form1
Public Sub New()
' This call is required by the designer.
InitializeComponent()
End Sub
Private Sub WebBrowser1_Navigating(sender As Object, e As WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
If e.Url.ToString.Contains("www.badwebsite.com") Then
e.Cancel = True
'WebBrowser1.Navigate("http://www.goodwebsite.com")
End If
End Sub
End Class