HTML Favicon.ico 不会在 Google Chrome 上显示 [英] HTML Favicon.ico won't show on Google Chrome

查看:83
本文介绍了HTML Favicon.ico 不会在 Google Chrome 上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个 HTML 页面,我想要的一件事是在标题旁边出现一个图标.

I am making a HTML page and one of the things I wanted was a favicon appearing next to the title.

我使用的是谷歌浏览器,我看到其他网站上的收藏夹图标可以正常工作,但我网站上的收藏夹图标不会显示.该站点位于我桌面上名为站点的文件夹中.

I'm using Google Chrome, I see favicons working on other websites, but the favicon on my website won't show up. The site is in a folder on my desktop named site.

favicon.ico 文件为 16x16,我使用在线生成器制作.

The favicon.ico file is 16x16, and I used an online generator to make it.

这是代码:

<!DOCTYPE html>
<html> 
    <head>
        <title></title>
        <link rel="shortcut icon" href="/favicon.ico" />
    </head>
    <body>
    </body>
</html>

推荐答案

由于您的 href 中有一个前导 /,因此您正在引用一个将位于根文件夹中的文件.如果您将页面放在计算机上的文件夹中,而不是从本地网络服务器提供它,则前导 / 将告诉浏览器查看文件系统的根文件夹.因此,浏览器希望文件位于 C:/favicon.ico 或类似位置,这可能不是您所期望的.

Since you have a leading / in your href, you are referencing a file that will be in the root-folder. In case you have your page in a folder on your computer, not serving it from a local webserver, the leading / will tell the browser to look in the root folder of your filesystem. So the browser expect the file to be at C:/favicon.ico or similar, which is probably not what you've expected.

如果 favicon.ico 与网页位于同一文件夹中,则只需删除前导斜杠,图标应该可见.

If you have the favicon.ico in the same folder as the web page, you could just remove the leading slash, and the icon should be visible.

<link rel="shortcut icon" href="favicon.ico" />

更新:

作为调试选项,您可以尝试添加一个您知道有效的标签.我从 StackOverflow 源中借用了这个片段.尝试用这个替换您的链接标签,看看您是否将 SO 徽标作为您的收藏夹图标.

As a debug option, your could try to add a tag that you know works. I borrowed this snippet from the StackOverflow source. Try replacing your link tag with this and see if you get the SO logo as your favicon.

<link rel="shortcut icon" 
      href="http://cdn.sstatic.net/stackoverflow/img/favicon.ico">

更新 2:

似乎在 Chromium 上报告了一个错误如果文件是在本地加载的,而不是通过网络服务器提供的,则不会显示网站图标.

It appears that there is a bug reported on Chromium where the favicon isn't displayed if the file is loaded locally, without being served through a webserver.

这篇关于HTML Favicon.ico 不会在 Google Chrome 上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆