Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleMake a Web browser that can only view certain URLs
KeywordsWeb browser, restrict, URL
CategoriesUtilities, 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
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated