|
|
Title | Make a Web browser that can only view certain URLs |
Keywords | Web browser, restrict, URL |
Categories | Utilities, Controls, Internet |
|
|
Use the WebBrowser control. In its BeforeNavigate2 event handler, examine the URL. If the URL is not allowed, set Cancel to True.
Also set Cancel to True in the NewWindow2 event handler so the user cannot open a link in a new window.
This example allows only URLs that begin with "http://www.vb-helper.com/"
|
|
Private Sub Form_Load()
WebBrowser1.Navigate "www.vb-helper.com/links.html"
End Sub
' Cancel any navigation that moves outside VB helper.
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)
Const TARGET = "http://www.vb-helper.com/"
Cancel = (LCase$(Left$(URL, Len(TARGET))) <> TARGET)
If Cancel Then MsgBox URL & " is blocked"
End Sub
' Don't let the user open a new window.
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel _
As Boolean)
Cancel = True
MsgBox "You cannot open a new window."
End Sub
|
|
|
|
|
|