Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-21-2006, 05:30 AM
BigNet BigNet is offline
Junior Member
 
Join Date: May 2004
Posts: 20
Default 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
Reply With Quote
  #2  
Old 01-21-2006, 05:49 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default 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!
Reply With Quote
  #3  
Old 01-21-2006, 07:51 AM
BigNet BigNet is offline
Junior Member
 
Join Date: May 2004
Posts: 20
Default 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
Reply With Quote
  #4  
Old 01-21-2006, 08:00 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default 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!
Reply With Quote
  #5  
Old 01-21-2006, 03:27 PM
Eddy-B Eddy-B is offline
Senior Member
 
Join Date: Feb 2002
Posts: 1,467
Default 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
Reply With Quote
  #6  
Old 01-22-2006, 01:06 AM
BigNet BigNet is offline
Junior Member
 
Join Date: May 2004
Posts: 20
Default 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
Reply With Quote
  #7  
Old 01-22-2006, 03:57 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: How to extract a favicon from a web page

It is not even being used, you can remove it.

MrBaseball34
Hook'Em Horns!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 08:51 AM.


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