Results 1 to 7 of 7

Thread: [RESOLVED] WebBrowser Help

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Resolved [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?

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: WebBrowser Help

    I get synx error on this line:
    If Left(cboAddress.Text, Len(lstValidURLs.List(i)) = lstValidURLs.List(i) Then

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: WebBrowser Help

    Here is correction
    Code:
       Add one more ) --------------------------------+
                                                      |
    If Left(cboAddress.Text, Len(lstValidURLs.List(i))) = lstValidURLs.List(i) Then

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    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:
    1. Dim FF As Integer, sItem As String
    2. lstValidURLs.Clear
    3. ' add code here to ensure file exists
    4. FF = FreeFile
    5. Open App.Path & "\Configuration Files\allowed.ini" For Input As #FF
    6. Do Until EOF(FF)
    7.     Line Input #FF, sItem
    8.     lstValidURLs.AddItem sItem
    9. Loop
    10. Close #FF
    11. GoodURL = False
    12. For I = 0 To lstValidURLs.ListCount - 1
    13.   If Left(Combo1.Text, Len(lstValidURLs.List(I))) = lstValidURLs.List(I) Then
    14.     GoodURL = True
    15.     Exit For
    16.   End If
    17. Next I
    18. If GoodURL Then
    19. 'Navigate To Selected Link One CLick
    20. w1.Navigate2 Combo1.Text
    21. Else
    22. End If
    23. End Sub

  6. #6
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    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

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    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
  •  



Click Here to Expand Forum to Full Width