将 favicon 添加到 JSF 项目并在中引用它

发布于 2024-11-07 07:13:40 字数 231 浏览 0 评论 0原文

如何将网站图标添加到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

青巷忧颜 2024-11-14 07:13:40

相对 href 是相对于当前请求 URI 的。它可能解析为无效的 URL。您需要在前面添加上下文路径,以便它相对于域根。

此外,rel 最好是快捷方式图标,以使其在旧版浏览器中也能工作。

如果使用 .ico 文件,您还需要确保它是真实 .ico 文件,而不是某些 .bmp 重命名为 .ico。您可以根据多种图像格式在此处生成一个。不过,您也可以只使用 .png.gif 文件。

总而言之,只要该文件位于,

WebContent
 |-- images
 |    `-- favicon.ico
 :

那么应该这样做:

<link rel="shortcut icon" type="image/x-icon" href="#{request.contextPath}/images/favicon.ico"/>

但是,如果您已将其作为 JSF 资源放置在 /resources 文件夹中,如下所示,

WebContent
 |-- resources
 |    `-- images
 |         `-- favicon.ico
 :

这将使其可以通过 访问>,那么这应该可以做到:

<link rel="shortcut icon" type="image/x-icon" href="#{resource['images/favicon.ico']}"/>

另请参阅:

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 be shortcut 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

WebContent
 |-- images
 |    `-- favicon.ico
 :

then this should do it:

<link rel="shortcut icon" type="image/x-icon" href="#{request.contextPath}/images/favicon.ico"/>

If you've however placed it as a JSF resource in the /resources folder as follows

WebContent
 |-- resources
 |    `-- images
 |         `-- favicon.ico
 :

which would make it accessible by <h:graphicImage name="images/favicon.ico">, then this should do it:

<link rel="shortcut icon" type="image/x-icon" href="#{resource['images/favicon.ico']}"/>

See also:

一片旧的回忆 2024-11-14 07:13:40

我使用了以下内容,它在 IE 和 Chrome 中都有效

<link rel="shortcut icon" href="#{resource['images/favicon.ico']}" type="image/x-icon" />   

I used the following and it works in both IE and Chrome

<link rel="shortcut icon" href="#{resource['images/favicon.ico']}" type="image/x-icon" />   
焚却相思 2024-11-14 07:13:40

由于JSF使用资源作为存储图像文件夹的容器,因此您可以执行以下操作;

<link rel="shortcut icon" type="image/x-icon" href="#{request.contextPath}/resources/images/favicon.ico"/>

Since JSF uses the resources as a container for storing the image file folder, you can do the following;

<link rel="shortcut icon" type="image/x-icon" href="#{request.contextPath}/resources/images/favicon.ico"/>
薄情伤 2024-11-14 07:13:40

作为旁注,在引用网站图标时我总是包含这两个内容:

<link rel="shortcut icon" type="image/x-icon" href="https://a.staticimageserver.com/img/favicon.ico" />
<link rel="icon" type="image/x-icon" href="https://a.staticimageserver.com/img/favicon.ico" />

As a side note, I always include both of these when referencing a favicon:

<link rel="shortcut icon" type="image/x-icon" href="https://a.staticimageserver.com/img/favicon.ico" />
<link rel="icon" type="image/x-icon" href="https://a.staticimageserver.com/img/favicon.ico" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文