将 favicon 添加到 JSF 项目并在中引用它
如何将网站图标添加到 JSF 项目并在 元素中引用它?
我尝试如下:
<h:head>
<link rel="icon" type="image/x-icon" href="images/favicon.ico"/>
...
</h:head>
但是,它没有显示任何图标。
How do I add a favicon to a JSF project and reference it in <link>
element?
I tried as below:
<h:head>
<link rel="icon" type="image/x-icon" href="images/favicon.ico"/>
...
</h:head>
However, it didn't show any favicon.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
相对
href
是相对于当前请求 URI 的。它可能解析为无效的 URL。您需要在前面添加上下文路径,以便它相对于域根。此外,
rel
最好是快捷方式图标
,以使其在旧版浏览器中也能工作。如果使用
.ico
文件,您还需要确保它是真实.ico
文件,而不是某些.bmp
重命名为.ico
。您可以根据多种图像格式在此处生成一个。不过,您也可以只使用.png
或.gif
文件。总而言之,只要该文件位于,
那么应该这样做:
但是,如果您已将其作为 JSF 资源放置在
/resources
文件夹中,如下所示,这将使其可以通过
访问>
,那么这应该可以做到:另请参阅:
A relative
href
is relative to the current request URI. Likely it resolved to an invalid URL. You need to prepend with the context path so that it becomes relative to the domain root.Also, the
rel
has better to beshortcut icon
to get it to work in older browsers too.In case of using an
.ico
file, you also need to ensure that it's a real.ico
file and not some.bmp
renamed to.ico
. You can generate one here based on several image formats. You can however also just use a.png
or.gif
file.All in all, provided that the file is located in
then this should do it:
If you've however placed it as a JSF resource in the
/resources
folder as followswhich would make it accessible by
<h:graphicImage name="images/favicon.ico">
, then this should do it:See also:
我使用了以下内容,它在 IE 和 Chrome 中都有效
I used the following and it works in both IE and Chrome
由于JSF使用资源作为存储图像文件夹的容器,因此您可以执行以下操作;
Since JSF uses the resources as a container for storing the image file folder, you can do the following;
作为旁注,在引用网站图标时我总是包含这两个内容:
As a side note, I always include both of these when referencing a favicon: