问题
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?
回答1:
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.
回答2:
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.
回答3:
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.
回答4:
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">
来源:https://stackoverflow.com/questions/9859431/why-is-favicon-not-visible