1

我尝试通过模板中的元标记来禁止 Internet Explorer。

template.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view locale="de_DE">
<h:head>
    <f:facet name="first">
        <h:outputText
            value="&lt;!--[if IE]&gt;
        &lt;h1&gt;No IE support.&lt;/h1&gt;
        &lt;![endif]--&gt;"
            escape="false" />
    </f:facet>
...

这样是行不通的。我怎样才能实现它?

4

1 回答 1

2

你所拥有的不是元标记,而只是一个 IE 条件注释,它根据最终用户是否使用 IE 有条件地显示一段 HTML 代码。要在页面正文中显示一段 HTML 代码,您必须将 HTML 代码<body>放在<head>.

<h:body>
    ...
    <h:outputText
        value="&lt;!--[if IE]&gt;
    &lt;h1&gt;No IE support.&lt;/h1&gt;
    &lt;![endif]--&gt;"
        escape="false" />
    ...
</h:body>

请注意,这不会以任何方式神奇地隐藏页面的其余部分。您必须通过包含一个<link>包含类似#content { display: none; }.


与具体问题无关,因为您基于已经使用 OmniFaces 的问题历史,您可能会发现<o:conditionalComment>在 JSF 中以开发人员友好的方式呈现 IE 条件注释很有帮助。

<h:body>
    ...
    <o:conditionalComment if="IE">
        <h1>No IE support.</h1>
    </o:conditionalComment>
    ...
</h:body>
于 2012-09-11T11:19:54.830 回答