Hi, many of you are may working on some sort of project with web browser related settings or information, so to day I'm gonna demonstrate how to get favicon in a tabbed web browser! It's is actually quite simple. But I've been searching for this "How to get favicon in web browser" and i found many answers, but not the right one. because in all the samples I've been seeing you can't type i.e "http://www.google.com" you need to type "www.google.com" because you need to add "http://" in the source of the request! But I'm gonna show you how to get your user to type "http://www.google.com" or "www.google.com" because the web browser need "http://" to get response from the server!
So first we need to declare our settings
We get our web browser to go to the url from txtAdress
We declare where we want to split the URL, and this is how we don't get stuck by typing "http://" in every URL!
"txtAdre
We get our web browser to TRY to split the string txtAdress.text that we declared earlier.
Checks the string if it have the "http://" in front of the URL
And finally gets the requested favicon in our imagebox!
Did this help? or not?
Leave a comment!
Sorry for my bad English! I'm from Norway
So first we need to declare our settings
VB.NET:
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(txtAdress.Text)
We get our web browser to go to the url from txtAdress
VB.NET:
Dim stringadress As String = txtAdress.Text
Dim outstring() As String
Dim Seps() As Char = {"h", "t", "t", "p", ":", "/", "/"}
VB.NET:
Try
outstring = stringadress.Split("h", "t", "t", "p", ":", "/", "/")
For i = 0 To outstring.Length - 1
outstring = stringadress.Split(Seps, StringSplitOptions.RemoveEmptyEntries)
MsgBox(outstring(i))
'We send the splitted string to a label that corrects it
txtAdressCheck.Text = outstring(i)
txtAdress.Text = "http://" & txtAdressCheck.Text 'We have removed the "http://" earlier and can now safe add "http://" to every splitted URL
We get our web browser to TRY to split the string txtAdress.text that we declared earlier.
VB.NET:
Dim url As Uri = New Uri(txtAdress.Text)
If url.HostNameType = UriHostNameType.Dns Then
Checks the string if it have the "http://" in front of the URL
VB.NET:
Dim browser As New WebBrowser
Dim iconURL = "http://" & txtAdressCheck.Text & "/favicon.ico"
Dim request As System.Net.WebRequest = System.Net.HttpWebRequest.Create(iconURL)
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim stream As System.IO.Stream = response.GetResponseStream()
Dim favicon = Image.FromStream(stream)
'Fav Icon
ImgFavIco.Image = favicon
And finally gets the requested favicon in our imagebox!
Did this help? or not?
Leave a comment!
Sorry for my bad English! I'm from Norway