2017-10-21 85 views

回答

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 
0

這是一個很容易的事情,你問。它看起來像這樣。您基本上會掛接導航和任何加載之前發生的導航事件。然後,您可以檢查任何您想要的網址,然後取消導航或重新路由到已批准的網站。

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