在网站实际加载之前,是否可以在Visual Basic中阻止网站?
例如,如果我尝试加载www.google.co.uk并点击它,则不会加载网站但会显示错误消息。我试过搜索但找不到我要找的东西。
答案 0 :(得分:1)
使用导航EventArgs。
示例:
Private Sub wbMain_Navigating(sender As Object, e As WebBrowserNavigatingEventArgs) Handles wbMain.Navigating
If e.Url.ToString = "https://www.google.co.uk" Then
MsgBox("Not allowed")
e.Cancel = True
Exit Sub
End If
End Sub
答案 1 :(得分:-1)
曾为:
'
'
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