|
-
May 17th, 2008, 04:54 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] WebBrowser Help
Ok lets say I have a comobox and a webrowser and a go button. Is there a way where when i git the go button it can read from a file ex. sites.ini and this file will show the approved sites. So when i press go it will check to see if that site is in the file. Also for example can it allow all the sites that is connected to that site. So lets say in the file i have www.google.com. can it also allow www.google.com/translate_t?
-
May 17th, 2008, 09:18 PM
#2
Re: WebBrowser Help
If you use InStr you can do what you want.
Example:
Read all the links from your ini file into a listbox then in a loop
Code:
Dim GoodURL As Boolean
'
'
'
GoodURL = False
For i = 0 To lstValidURLs.ListCount-1
If InStr(cboAddress.Text, lstValidURLs.List(i)) > 0 Then
GoodURL = True
Exit For
End If
Next i
If GoodURL Then
'
' Do what you want here for a good URL link
'
End If
'
'
'
NOTE:
If you want to make sure that the link starts with a valid link from your ini then you can use the following IF statement instead of the one I posted above:
Code:
'
'
'
'
For i = 0 To lstValidURLs.ListCount-1
If Left(cboAddress.Text, Len(lstValidURLs.List(i)) = lstValidURLs.List(i) Then
GoodURL = True
Exit For
End If
Next i
'
'
'
'
Last edited by jmsrickland; May 17th, 2008 at 09:39 PM.
-
May 17th, 2008, 11:23 PM
#3
Thread Starter
Fanatic Member
Re: WebBrowser Help
I get synx error on this line:
If Left(cboAddress.Text, Len(lstValidURLs.List(i)) = lstValidURLs.List(i) Then
-
May 17th, 2008, 11:52 PM
#4
Re: WebBrowser Help
Here is correction
Code:
Add one more ) --------------------------------+
|
If Left(cboAddress.Text, Len(lstValidURLs.List(i))) = lstValidURLs.List(i) Then
-
May 18th, 2008, 12:31 AM
#5
Thread Starter
Fanatic Member
Re: WebBrowser Help
Ok this is how the code works, In my web browser you cannot go to any site. that is not in the file. The first time you go to a allowed site you can go to any other site after that its like it dosent check the file no more. Whey is that?
My Code:
vb Code:
Dim FF As Integer, sItem As String
lstValidURLs.Clear
' add code here to ensure file exists
FF = FreeFile
Open App.Path & "\Configuration Files\allowed.ini" For Input As #FF
Do Until EOF(FF)
Line Input #FF, sItem
lstValidURLs.AddItem sItem
Loop
Close #FF
GoodURL = False
For I = 0 To lstValidURLs.ListCount - 1
If Left(Combo1.Text, Len(lstValidURLs.List(I))) = lstValidURLs.List(I) Then
GoodURL = True
Exit For
End If
Next I
If GoodURL Then
'Navigate To Selected Link One CLick
w1.Navigate2 Combo1.Text
Else
End If
End Sub
-
May 18th, 2008, 01:35 AM
#6
Re: WebBrowser Help
Use the before navigate event.
Code:
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)
'put your URL validation under this event
'put your code here
End Sub
-
May 18th, 2008, 10:30 AM
#7
Thread Starter
Fanatic Member
Re: WebBrowser Help
Thankyou a common mistake overlooked!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|