Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   General (http://www.delphipages.com/forum/forumdisplay.php?f=2)
-   -   How to extract a favicon from a web page (http://www.delphipages.com/forum/showthread.php?t=156276)

BigNet 01-21-2006 06:30 AM

How to extract a favicon from a web page
 
Is there a component in delphi that helps me to extract a favicon from a website like a web browser can do.

Thanks

MrBaseball34 01-21-2006 06:49 AM

RE: How to extract a favicon from a web page
 
Here is some code I previously posted on Experts-Exchange:

[DELPHI]
function GetFavIcon(Doc:IHTMLDocument2):String;
var
All: IHtmlElementCollection;
E: IhtmlElement;
Element: TElementInfo;
x: INteger;
ELink: IHTMLLinkElement;
DocLoc: String;
begin
DocLoc := Doc.location.toString;
DocLoc := Copy(DocLoc, 1, Length(DocLoc)-1);
All := Doc.Get_all;
if (All <> nil) then
begin
for x := 0 to All.length - 1 do
begin
E := All.item(x, 0) as IHTMLElement;
if E.tagName = 'LINK' then
begin
ELink := E as IHTMLLinkElement;
if ( Pos('SHORTCUT', UpperCase(ELink.rel)) > 0 ) or
( Pos('ICON', UpperCase(ELink.rel)) > 0 ) then
Result := DocLoc + ELink.href;
end;
end;
end;
end;

procedure TForm1.WebBrowser1NavigateComplete2(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
Label1.Caption := GetFavIcon(WebBrowser1.Document as IHTMLDocument2);
end;
[/DELPHI]

This only returns the LINK to the icon, not the icon itself.
Remember, the favicon is only a bitmap, not an ICON.

However, since IE caches the FavIcon based upon the domain,
not all pages may have this particular link tag. I don't
know about Mozilla, Netscape, etc...



MrBaseball34
Hook'Em Horns!
http://www.austinmetrobaseball.com/texas.gif

BigNet 01-21-2006 08:51 AM

RE: How to extract a favicon from a web page
 
I had copy your source code MrBaseball34 but it does not works because it not reconize the classes you are in use ex : IHTMLDocument2, IHTMLElement,...

Can you explain me more clearly please.
Thanks

MrBaseball34 01-21-2006 09:00 AM

RE: How to extract a favicon from a web page
 
If you are using D6 or above, it is in unit MSHTML,
otherwise, you have to import the MS HTML Type Library.
Project->Import Type Library, scrolldown to see the
Microsoft HTML somehting or other and click create unit.
Then add MSHTML_TLB to your uses.


MrBaseball34
Hook'Em Horns!
http://www.austinmetrobaseball.com/texas.gif

Eddy-B 01-21-2006 04:27 PM

RE: How to extract a favicon from a web page
 
favicon.ico is just another file on a webserver. You can use any HTML component to get it. It is usually a 16x16 icon file and is located on the server root (i.e. www.google.com/favicon.ico)


Eddy-B

Please click Accept as answer if this helped

BigNet 01-22-2006 02:06 AM

RE: How to extract a favicon from a web page
 
Thanks Mr BaseBall, but I have not found the unit that makes me use the TElementInfo.

Can you help me please.
Thanks

MrBaseball34 01-22-2006 04:57 AM

RE: How to extract a favicon from a web page
 
It is not even being used, you can remove it.

MrBaseball34
Hook'Em Horns!
http://www.austinmetrobaseball.com/texas.gif


All times are GMT. The time now is 05:48 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.