HTML图标将不会显示在谷歌浏览器上 [英] HTML favicon won't show on google chrome

查看:154
本文介绍了HTML图标将不会显示在谷歌浏览器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个未发布的HTML页面。我想要做的事情之一是添加一个图标出现在标题旁边。我使用的是谷歌浏览器,我注意到其他网站在浏览器中显示在磁贴旁边的图标,但我试图显示的图标不会显示。该网站位于我的桌面命名网站上的文件夹中。这是代码:

 <!DOCTYPE html> 
< html>
< head>
< title>< / title>
< link rel =快捷图标href =/ favicon.ico/>
< / head>
< body>
< / body>
< / html>


解决方案

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



如果您在网页的同一文件夹中拥有 favicon.ico ,则可以删除前导斜杠,并且图标应该可见。

 < link rel =快捷图标href =favicon.ico/> 

更新:

作为一个调试选项,您可以尝试添加您熟悉的标签。我借用了StackOverflow源代码片段。尝试用此替换您的链接标记,看看您是否将SO徽标作为您的图标。

 < link rel =快捷方式图标
href =http://cdn.sstatic.net/stackoverflow/img/favicon.ico>

更新2:

似乎有报告了错误 Chromium,其中如果文件在本地加载,则不会显示收藏图标。


I am making a HTML page that is unpublished . One of the things I wanted to do was add a favicon to appear next to the title. I'm using google chrome and I noticed that other websites have favicons that appear next to the tile in the browser, but the one I'm trying to display won't show up. The site in in a folder on my desktop named site. This is the code:

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

解决方案

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.

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" />

Update:

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">

Update 2:

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图标将不会显示在谷歌浏览器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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