Solved

Retriving Favicon.ico from an URL

Posted on 2004-09-22
2
823 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

728 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