views:

58

answers:

3

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.

+1  A: 

The favicon is a separate file. It is not part of the page HTML.

You will need to fetch it in a separate call.

Oded
+2  A: 

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.

Maushu
+2  A: 

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

Sheng Jiang 蒋晟
+1 for the control not having this feature implemented
Maushu