
Stopping WebBrowser from navigating to local files.
Save the "approved" strings in an INI file, the Registry, or a database.
Load them up at runtime into an array and loop through the array instead of
using the logic below. You can have 1,000 things in the array and the code
won't change at all:
for icount = lbound(myarray) to ubound(myarray)
if ucase(left(url,len(myarray(icount)))) = ucase(myarray(icount)) then
bOK = true
exit for
end if
next icount
if bOK then navigate...
This was written in OE, so the syntax may be off, but you get the idea. Of
course, this is just streamlining the original brute-force method. There
may be (and probably is) a better alternative altogether. I just can't
think of one right now. ;)
--
Regards,
Gregory Silvano
http://www.codehound.com
Free Internet Search Engine for VB Developers
Quote:
> Hello,
> I posted some code below. I found if I restrict the user from the get go,
> I don't have a problem. Logically this works but I feel that I went
> around the world to get to it. My concern is, what if there's something
> is included in the navigating in time? An example, "http_new://". If
> something new comes out or I missed something, this browser will be
> obsolete in time. Does anyone have a better logic to tackle this? Thanks
> again.
> Jerry
> Here's the code:
> Private Sub wbMain_BeforeNavigate2(index As Integer, ByVal pDisp As
> Object, URL As Variant, Flags As Variant, TargetFrameName As Variant,
> PostData As Variant, Headers As Variant, Cancel As Boolean)
> If LCase(Left(URL, 16)) = "c:\source_files" Or _
> LCase(Left(URL, 7)) = "http://" Or _
> LCase(Left(URL, 8)) = "https://" Or _
> LCase(Left(URL, 7)) = "mailto:" Or _
> LCase(Left(URL, 6)) = "ftp://" Or _
> LCase(Left(URL, 24)) = "file:///c:/source_files" Or _
> LCase(Left(URL, 11)) = "javascript:" Then
> wb1.navigate URL
> Else
> Cancel=True
> End If
> > You can monitor the URL in the BeforeNavigate2 event of the WebBrowser
> > control. Just don't allow them if they are about to navigate to a local
> > file not located in your supportFiles directory.
> > --
> > Regards,
> > Gregory Silvano
> > http://www.codehound.com
> > Free Internet Search Engine for VB Developers
> > > I have a custom webbrowser control. The user can surf the net as usual
> > > but if they c:\ in the navigation ComboBox, they can get to the root
of
> > > the winNt box and subsequently any directory on the machine. What are
my
> > > possible solutions for this? Also if I block all access to the local
> > > files, I still need to keep one directory available for supporting
files,
> > > i.e., local .html files and text files that are read at run-time.
> > > Basically the entire file system needs to be invisible to the
webbrowser
> > > control except one folder, c:\supportFiles\
> > > Thanks for any help
> > > Jerry