0

I have a script which allows to display favicons based on the url: Example

If you look at the example you will see two links, one linking to Google and the other to a popular dutch news website. As you can see the Google favicon is retrieved by the script while the other is not. How is this possible? What is causing this? If I go to the website I can see they do have a favicon. What can I change in the code to retrieve this favicon?

Youss
  • 4,196
  • 12
  • 55
  • 109
  • 1
    In firebug I can see that the request for www.nu.nl/favicon.ico returns returns a `404` (not found) respons. – Cyclonecode Mar 25 '12 at 10:30
  • OK I understand now, there is only a path for the img and not really an img present in source code. Is there nothing 'simple' I can do to make it work?? – Youss Mar 25 '12 at 10:37
  • Why am I getting a downvote..? – Youss Mar 25 '12 at 10:37

4 Answers4

8

Because favicon for nu.nl is stored under http://www.nu.nl/images/favicon.ico

Check out quick and dirty solution: http://jsbin.com/eselap/2/edit, which has hardcoded URLs. Ideally, you should request the page, parse it and find URL of favicon.

galymzhan
  • 5,505
  • 2
  • 29
  • 45
  • Why should that matter..? Is there something I can change in the code to retrieve this sort of 'urls' and there favicon? – Youss Mar 25 '12 at 10:33
  • Thanks, I get it now:) (Do you think there is a way of dynamicly adding the url like: `favicons: { 'var-this or function-that??': '/images/favicon.ico' }` – Youss Mar 25 '12 at 10:47
  • @Youss I don't understand what are you asking about. Better to edit question and add details probably? – galymzhan Mar 25 '12 at 10:54
4

The script only looks for a specific icon file in the root of the website, but the icon file could be named anything, and be placed in any folder in the site.

If you want the script to work for any favicon, you have to get the HTML source of the page, parse that to find the favion information, and look for the icon where it actually is.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
2

If you access http://www.nu.nl/favicon.ico directly, you will found that is not a favicon image.

The path for favicon is configurable.

xdazz
  • 158,678
  • 38
  • 247
  • 274
2

In the head of the page nu.nl there is following link-tag which defines the favicon in the path /images:

<link type="image/x-icon" href="/images/favicon.ico" rel="shortcut icon">
scessor
  • 15,995
  • 4
  • 43
  • 54