我需要我的应用程序在 IE9 文档标准中运行,但我不明白为什么它会自动在 IE8 文档标准中呈现。
我使用的是 JSF 2.1.17 和 Primefaces 3.4,在 Glassfish 3.1.2 中运行。我的 IDE 是 Netbeans-7.1.2。当我在 IE 中打开开发人员工具时,在“HTML”选项卡下显示:
<--!DOCTYPE html-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
但是,在“脚本”选项卡下它显示:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML lang=en xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<HEAD>
<META content="IE=8.0000" http-equiv="X-UA-Compatible">
我查看了我所有的页面和模板,但我在任何地方都找不到上面显示的 meta content="IE=8.0000"或 !DOCTYPE。这很奇怪。
我所有的页面都有:
<!DOCTYPE html>
我的主模板是这样的:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
其他页面有:
<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
template="/layout/someFile.xhtml" >
以下是我尝试过的:
1) 将 Glassfish JSF 更新到 2.1.17,因为我读到旧版本的 Mojarra 存在一个错误,导致它忽略 DOCTYPE。
2)我补充说:
<meta http-equiv="X-UA-Compatible" content="IE=9" >
到每个页面,希望它能强制执行 IE9,但这没有用。
3) 然后我尝试使用 content="IE=Edge",仍然没有任何变化。
4) 我将 DOCTYPE 更改为:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
不确定 XHTML 是否需要这种严格的 DOCTYPE 才能正确呈现。但这没有用。
任何帮助都会很棒。我做了很多研究试图解决这个问题,但是我是网络开发的新手,所以我的理解非常有限。
最佳答案
I added:
<meta http-equiv="X-UA-Compatible" content="IE=9" >
to every page, hoping it would enforce IE9, but this did not work.
根据MSDN document在这个元标记上,
The X-UA-Compatible header isn't case sensitive; however, it must appear in the header of the webpage (the HEAD section) before all other elements except for the title element and other meta elements.
这必须出现在 之前 所有其他元素预期 <title>
及其他<meta>
元素。如果您仔细研究 JSF/PrimeFaces 生成的 HTML,您会发现有一个 PrimeFaces 特定的 <link>
。在将阻止 X-UA-Compatible
的元素之前header 从做它的工作。
PrimeFaces supports <h:head>
的几个方面这样你就可以控制头部资源的排序。以下应该为您完成:
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="IE=9" />
</f:facet>
同样,这是 PrimeFaces 特有的,而不是标准 JSF。
关于jsf - IE9渲染 IE8文档标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14840259/