关于X-UA-Compatible
目前绝大多数网站都用
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" >
来作为IE8的兼容方法,虽然微软将IE向标准迈进了一大步,而事实上IE8还存在一系列渲染的奇怪现象是不争的事实。
谁让IE6那么多呢,或许2014年以后我们可以有更多的时间去关心IE8,而不是IE6或者IE7。
在X-UA-Compatible中可用的方法有:
<meta http-equiv="X-UA-Compatible" content="IE=5" >
<meta http-equiv="X-UA-Compatible" content="IE=7" >
<meta http-equiv="X-UA-Compatible" content="IE=8" >
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
其中最后一行是永远以最新的IE版本模式来显示网页的。
另外加上
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" >
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" >
而使用,Emulate模式后则更重视<!DOCTYPE>所以目前来说还是以
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" >
推荐方式
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
</head>
X-UA-Compatible是针对IE8新加的一个设置,对于IE8之外的浏览器是不识别的,这个区别与content="IE=7"在无论页面是否包含<!DOCTYPE>指令,都像是使用了 Windows Internet Explorer 7的标准模式。而content="IE=EmulateIE7"模式遵循<!DOCTYPE>指令。对于多数网站来说,它是首选的兼容性模式。
为了避免制作出的页面在IE8下面出现错误,建议直接将IE8使用IE7进行渲染。也就是直接在页面的header的meta标签中加入如下代码:
这样我们才能使得页面在IE8里面表现正常!
浏览器市场份额的激烈竞争,给网页设计开发人员带来了兼容性设计的麻烦。仅IE浏览器就有好几个主流版本,IE6、IE7、IE8 等等。当然使用诸如 IETester,多版本 IE 共存解决方案之类的第三方集成工具,可以方便代码调试。但我们总需要找寻一种更为省时省力的方法。
X-UA-Compatible 是针对 IE8 版本的一个特殊文件头标记,用于为 IE8 指定不同的页面渲染模式。由于当下 IE6 和 IE7 使用率依然较高,综合考虑,启用 IE8 版本的 X-UA-Compatible 兼容模式显得相当重要。
各种兼容模式代码示例如下:
1.<meta http-equiv="X-UA-Compatible" content="IE=5" />
像是使用了 Windows Internet Explorer 7 的 Quirks 模式,这与 Windows Internet Explorer 5 显示内容的方式很相似。
2.<meta http-equiv="X-UA-Compatible" content="IE=7" />
无论页面是否包含 <!DOCTYPE> 指令,均使用 Windows Internet Explorer 7 的标准渲染模式。
3.<meta http-equiv="X-UA-Compatible" content="IE=8" />
开启 IE8 的标准渲染模式,但由于本身 X-UA-Compatible 文件头仅支持 IE8 以上版本,因此等同于冗余代码。
4.<meta http-equiv="X-UA-Compatible" content="edge" />
Edge 模式通知 Windows Internet Explorer 以最高级别的可用模式显示内容,这实际上破坏了“锁定”模式。即如果你有IE9的话说明你有IE789,那么就调用高版本的那个也就是IE9。
5.<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
如果IE有安装Google Chrome Frame,那么就走安装的组件,如果没有就和<meta http-equiv="X-UA-Compatible" content="edge" />一样。
说明:针对IE 6,7,8等版本的浏览器插件Google Chrome Frame,可以让用户的浏览器外观依然是IE的菜单和界面,但用户在浏览网页时,实际上使用的是Google Chrome浏览器内核。
6.<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
EmulateIE7 模式通知 Windows Internet Explorer 使用 <!DOCTYPE> 指令确定如何呈现内容。标准模式指令以Windows Internet Explorer 7 标准模式显示,而 Quirks 模式指令以 IE5 模式显示。与 IE7 模式不同,EmulateIE7 模式遵循 <!DOCTYPE> 指令。对于多数网站来说,它是首选的兼容性模式。
目前,在开发AngularJS项目时(只支持IE8及以上版本或chrome/firefox),而有些同事IE8登录却还提示“请使用IE8及以上版本或chrome/firefox,如果您使用IE8,请在”工具”菜单中,调整为非”兼容性视图”!
解决方法:
1.将项目中的.html及.jsp文件的<head>的最前面加上
<meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
(即如上meta加在其它meta之前)
如下所示:
- <html>
- <head>
- <meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta http-equiv="pragma" content="no-cache"/>
- <meta http-equiv="cache-control" content="no-cache"/>
- <meta http-equiv="expires" content="0"/>
- </head>
- ...
- </html>
2.选择“工具”菜单栏,点击“兼容性视图设置(B)”
打开如下弹出框,将“在兼容性视图中显示Intranet站点(I)、在兼容性视图中显示所有网站(E)”这两项前面的勾选框勾选掉(即不勾选上)