Why is favicon not visible

帅比萌擦擦* 提交于 2019-12-25 05:16:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!