October 21, 2018
Hot Topics:

Creating a Web Browser

  • November 20, 2002
  • By Karl Moore
  • Send Email »
  • More Articles »

If you're creating a custom browser, you may wish to restrict certain Web sites. You do this by intercepting the request to visit a Web site with the BeforeNavigate2 event.

Here's a chunk of sample code that doesn't allow the user to visit playboy.com:

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(1, URL, "playboy.com") Then
        Cancel = True
        MsgBox "Sorry, that site is restricted!"
    End If

End Sub

This works by checking the passed URL (Web Address). If it contains the string 'playboy.com', the action is cancelled and a message box displayed. Otherwise, if everything is A-OK, access to the site is allowed.

It's worth noting that this code will work equally as well in either the BeforeNavigate or BeforeNavigate2 events. Users of Visual Basic 6 will only have BeforeNavigate2, whilst Visual Basic 5 folk may have both. There is very little different between the two methods. For more information, consult the help file.

Page 6 of 8

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date