Internet explorer 如何在JSF中使用InternetExplorer条件注释?
这是我在Eclipse中的源代码文件:Internet explorer 如何在JSF中使用InternetExplorer条件注释?,internet-explorer,jsf,jsf-2,facelets,conditional-comments,Internet Explorer,Jsf,Jsf 2,Facelets,Conditional Comments,这是我在Eclipse中的源代码文件: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!--[if lt IE 9]> <script
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
</body>
</html>
当我在IE9中查看此内容时,它会呈现以下文本:
<!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->
如果我查看来源,它会说:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
</body>
</html>
一旦FacesServlet提供服务,源代码发生更改的原因是什么?已知问题,JSF呈现将跳过注释。您可以使用
和HTML实体来解决这个问题。您还可以使用OmniFaces
以更好的方式解决它
呈现条件注释。条件注释是IE特有的特性,它使开发人员能够根据客户端是否在使用IE,甚至是哪个版本,对HTML块进行注释。它们通常与CSS样式表结合使用,如下所示:
<!--[if lte IE 7]>
<link rel="stylesheet" href="ie6-ie7.css" />
<![endif]-->
此组件旨在解决此问题
<o:conditionalComment if="lte IE 7">
<link rel="stylesheet" href="ie6-ie7.css" />
</o:conditionalComment>
请注意,您不能将其与
一起使用,因为它将被隐式地重新定位为
的直接子级
<h:outputText
value="<!--[if lte IE 7]><link rel="stylesheet" href="ie6-ie7.css" /><![endif]-->"
escape="false" />
这项工作:
<h:outputText escape="false" value="<!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->"></h:outputText>
我使用f:verbatim,更干净 比如说
<f:verbatim>
<!--[if gte IE 8]>
<script type="text/javascript">
//<![CDATA[
/** Javascript **/
//]]>
</script>
<![endif]-->
</f:verbatim>
注意:自JSF2.0(2009年12月)以来,该标签已被弃用。它仅用于JSP您不需要将脚本部分放在那里。您还可以将其拆分,并将脚本标记保留在outputText之外。它仅用于JSP。
<f:verbatim>
<!--[if gte IE 8]>
<script type="text/javascript">
//<![CDATA[
/** Javascript **/
//]]>
</script>
<![endif]-->
</f:verbatim>