Results 1 to 18 of 18

Thread: How do you make the webbrowser visit more than one page?

  1. #1

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    54

    Question How do you make the webbrowser visit more than one page?

    For example I want it to go to one page then when it finishes loading go to another. So I want to to go one from one from one all with the click of a button. Is this possible?



    P.S: Another question, just to kill two birds with one stone, how do I make it so whatever is written in a textbox is added to the browser url. For example if the users write 'xyz' that it will add it to Google.com/ as an example and make it Google.com/xyz?

  2. #2
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: How do you make the webbrowser visit more than one page?

    Imagine WebBrowser1.Url was "www.google.com" and textbox1 text was "/youtube"
    VB.NET Code:
    1. WebBrowser1.Url += TextBox1.Text
    webbrowser1.url would be "www.google.com/youtube"

  3. #3

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    54

    Re: How do you make the webbrowser visit more than one page?

    Thank you for answering the second question do you know the answer for the first?

  4. #4
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: How do you make the webbrowser visit more than one page?

    Have something like this
    Code:
    'DECLARATIONS:
    dim I as Integer = 0
    '-----------------------------------------
    'WEBBROWSER1 DOCUMENT COMPLETED
    I = + 1
    '-----------------------------------------
    'BUTTON 1 CLICK
    If (I = 0) Then
              WebBrowser1.Navigate("www.google.com")
    ElseIf (I = 1) Then
              WebBrowser1.Navigate("www.youtube.com")
    EndIf

  5. #5

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    54

    Re: How do you make the webbrowser visit more than one page?

    Can you reexplain the second part? How can I incorporate question 1 and 2?

  6. #6

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    54

    Re: How do you make the webbrowser visit more than one page?

    Sorry it didnt work. When I click the button it goes straight to youtube, not first google then when it finishes loading to youtube. Any workarounds?

  7. #7

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    54

    Re: How do you make the webbrowser visit more than one page?

    Also when I try to add " WebBrowser1.Url += TextBox1.Text " it gives me an error that says: Operator '+' is not defined for types 'System.Uri' and 'String'.

  8. #8
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: How do you make the webbrowser visit more than one page?

    Quote Originally Posted by kytro360 View Post
    For example I want it to go to one page then when it finishes loading go to another. So I want to to go one from one from one all with the click of a button. Is this possible?



    P.S: Another question, just to kill two birds with one stone, how do I make it so whatever is written in a textbox is added to the browser url. For example if the users write 'xyz' that it will add it to Google.com/ as an example and make it Google.com/xyz?
    I'm confused about the button. You want to move on to next page when the first page has finished loading OR when the button is clicked?
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  9. #9

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    54

    Re: How do you make the webbrowser visit more than one page?

    Ok when they click the button I want it to go to one site then when it finishes loading the page it will visit another and vice versa. Also there will be a text box next to the button where try fill out there site ad the URL that the button visits will have the URL plus whatever they wrote in the text box as the web address

  10. #10
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: How do you make the webbrowser visit more than one page?

    vb.net Code:
    1. Dim isMainUrl As Boolean
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         isMainUrl = True
    5.         WebBrowser1.Navigate("http://www.google.com/")        '' or whatever
    6.     End Sub
    7.  
    8.     Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    9.         If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
    10.             If isMainUrl Then
    11.                 isMainUrl = False
    12.                 WebBrowser1.Navigate(WebBrowser1.Url.AbsoluteUri & TextBox1.Text)
    13.             End If
    14.         End If
    15.     End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  11. #11

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    54

    Re: How do you make the webbrowser visit more than one page?

    Thx for the code Pradeep but will it work for my first question about the webbrowser visiting more than one site?

  12. #12
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: How do you make the webbrowser visit more than one page?

    Quote Originally Posted by kytro360 View Post
    Thx for the code Pradeep but will it work for my first question about the webbrowser visiting more than one site?
    yes
    .
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  13. #13

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    54

    Re: How do you make the webbrowser visit more than one page?

    But in the code all I see is a spot for one URL?

  14. #14
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: How do you make the webbrowser visit more than one page?

    That's what you need for what you are telling till now.

    1. Browse to a url.
    2. Append the textbox text to that url and browse to this new url.

    That's all.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  15. #15
    New Member
    Join Date
    Jun 2011
    Posts
    9

    Re: How do you make the webbrowser visit more than one page?

    Hi, thanks Pradeep1210 i needed that code too thanks

    I did a little noob modified code from yours for navigate a listbox, is incomplete but this can help to the user that did the question :

    Code:
        Dim isMainUrl As Boolean
         
            Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                isMainUrl = True
                WebBrowser1.Navigate(textbox1.text)        '' or whatever
            End Sub
         
            Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
                If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
                    If isMainUrl Then
                        isMainUrl = False
              TextBox1.Text = (ListBox1.Items(ListBox1.SelectedIndex).ToString)
                        WebBrowser1.Navigate(TextBox1.Text)
                   ListBox1.Items.Remove(ListBox1.SelectedItem)
                ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
                Button1.PerformClick()
                    End If
                End If
            End Sub

  16. #16

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    54

    Re: How do you make the webbrowser visit more than one page?

    Hey Carlos will your code work or example if I have the sites in a list box and it visits all the sites in the list?

  17. #17
    New Member
    Join Date
    Jun 2011
    Posts
    9

    Re: How do you make the webbrowser visit more than one page?

    Yes it will
    You only have to select the first item(url) in the listbox then press the button and automatically it will visit each one, the code have bugs for example, you need to select the fist item int he listbox or when the listbox get empty will give you an error.

    Try it ^^

    PD:Sorry for my english im a spanish guy D:

  18. #18

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    54

    Re: How do you make the webbrowser visit more than one page?

    Sweet thanks Carlos I think your code will help a ton in my project. Also I wanna add a label that changes to success if the page was successfully loaded or failed if it didn't work. Should I add if then statements?

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