问题描述
我试图使用IE条件注释来声明一个CSS资源:
I'm trying to use an IE conditional comment to declare a CSS resource:
<h:outputStylesheet name="common.css" library="css" />
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="#{resource['css:ie.css']}" />
<![endif]-->
然而,这似乎不起作用。我在生成的HTML输出中看到这一点:
However, that doesn't seem to work. I'm seeing this in my generated HTML output:
<link type="text/css" rel="stylesheet" href="/context/faces/javax.faces.resource/common.css?ln=css" />
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="/context/faces/javax.faces.resource/ie.css?ln=css"/>
<![endif]-->
它没有条件注释就可以正常工作。我没有使用上下文参数。这是如何引起的,我该如何解决呢?
It works fine without the conditional comment. I'm not using the context parameter javax.faces.FACELETS_SKIP_COMMENTS
. How is this caused and how can I solve it?
推荐答案
内容。最好的办法是将它放在< h:outputText escape =false>
中,如下所示:
This indeed won't work as Facelets implicitly HTML-escapes the comment's contents. Your best bet is to put it in a <h:outputText escape="false">
as follows:
这是一个丑陋的线。 具有:
<h:outputText value="<!--[if IE]><link rel="stylesheet" type="text/css" href="/#{resource['css:ie.css']}" /><![endif]-->" escape="false" />
This is however a line of ugliness. The OmniFaces JSF utility library has a <o:conditionalComment>
for exactly this purpose:
无关具体问题,你不是真正使用库
属性的正确方法。它应该标识一个共同的主题,而不是放置文件的子文件夹,只是把该子文件夹放在 name
属性中。另请参见
Unrelated to the concrete problem, you are not really using the library
attribute the right way. It should identify a common "theme", not the subfolder where the files are placed in, just put that subfolder in the name
attribute instead. See also What is the JSF resource library for and how should it be used?
<h:outputStylesheet name="css/common.css" />
<o:conditionalComment if="IE">
<link rel="stylesheet" type="text/css" href="#{resource['css/ie.css']}" />
</o:conditionalComment>
这篇关于<! - [if IE]>条件注释在Facelets中呈现为HTML转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!