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?
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:
WebBrowser1.Url += TextBox1.Text
webbrowser1.url would be "www.google.com/youtube"
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?
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
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?
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?
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'.
Re: How do you make the webbrowser visit more than one page?
Quote:
Originally Posted by
kytro360
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?
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
Re: How do you make the webbrowser visit more than one page?
vb.net 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("http://www.google.com/") '' 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
WebBrowser1.Navigate(WebBrowser1.Url.AbsoluteUri & TextBox1.Text)
End If
End If
End Sub
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?
Re: How do you make the webbrowser visit more than one page?
Quote:
Originally Posted by
kytro360
Thx for the code Pradeep but will it work for my first question about the webbrowser visiting more than one site?
yes
.
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?
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.
Re: How do you make the webbrowser visit more than one page?
Hi, thanks Pradeep1210 i needed that code too thanks :D
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
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?
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:
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?