Solved

Retriving Favicon.ico from an URL

Posted on 2004-09-22
2
801 Views
Last Modified: 2010-04-16
Hi,

How can I retrive a Favicon.ico from an URL and store it locally? I want to do it on the fly and the URL will not be in my IE Favorites, but it would certainly be among the visited sites.

Let me explain it further, I have a TWebBrowser component and a button-click will fetch the favicon.ico from the URL (currently browsed by TWebBrowser). So, there may be a possibility to grab the .ico from IE history folder (just a hint, I am very much open to other solutions also).

So, ideally I will pass the URL to a function and it will store the icon locally.

regards,
Partha



0
Comment
Question by:perthg
2 Comments
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 500 total points
ID: 12131214
you could use the EddieShipman example from here http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20986816.html#11053973

or maybe this method (just an idea) using urlmon: it get the favicon.icon from the homepage of whatever page you're browsing:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw,urlmon, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    Button2: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    Function GetFavIcon( Url: string;dest: String): Boolean ;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

Function TForm1.GetFavIcon( Url: string;dest: String): Boolean;
var i: Integer;
begin
If Pos('HTTP://',UPPERCASE(URL)) > 0 then
   delete(Url,1,7);
i := pos('/',url);
If i > 0 then
   Url := 'http://'+copy(url,1,i);

   Result := UrlDOwnloadToFile(nil,PCHar(Url+'favicon.ico'),Pchar(dest),0,nil) = 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21141761.html');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
Url :STring;
begin
If GetFavIcon(WebBrowser1.LocationUrl,'c:\favicon.ico') then
   Image1.Picture.LoadFromFile('c:\favicon.ico')
else
   Image1.Picture := nil;
end;

end.

F68;
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12135382
Whoa, Ferruccio68, thanks for the link...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best Firemonkey component pack 1 116
oracle global variables 4 76
How to debug For loops? 3 56
TServerSocket - file via sendbuf or Text via sendtext ? 1 65
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question