Solved

Retriving Favicon.ico from an URL

Posted on 2004-09-22
2
787 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now