Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a websites favicon when using the WebBrowser control?

I have a Windows Forms WebBrowser control embedded in my application. Is there any way to get a web pages favicon using either the WebBrowser or HtmlDocument API? Even obtaining it from the local file system would suffice. Downloading the icon as a separate operation would be a last resort...

Thanks.

like image 913
Philip Wallace Avatar asked Dec 12 '22 22:12

Philip Wallace


2 Answers

Just download the /favicon.ico file using a GET or something similar (like you would for any other file).
You can also parse the page to find the favicon that might be also a png. By default it's an ICO file.

The location of favicon file is usually in <link rel="shortcut icon" href="/favicon.ico" /> in the <head> node of the page.

Also, some browsers by default try to download /favicon.ico (that is, the favicon.ico file in the root folder of the website) without checking the page for that element.

Other idea would be using Google's S2:

http://www.google.com/s2/favicons?domain=youtube.com (Try it)
This will get you a 16x16 PNG image of youtube's ICO favicon.

http://www.google.com/s2/favicons?domain=stackoverflow.com (Try it)
This will get you the stackoverflow favicon in the same format.

It might seem awesome but don't forget, this Google service is not officially supported and they might remove it at anytime.

like image 134
Diogo Gomes Avatar answered Dec 15 '22 13:12

Diogo Gomes


And the webbrowser control doesn't have an address bar, so it does not have application programming interface for address bar features like favicon.

like image 26
Sheng Jiang 蒋晟 Avatar answered Dec 15 '22 14:12

Sheng Jiang 蒋晟