<
meta
http-equiv
=
"X-UA-Compatible"
content
=
"IE=edge,chrome=1"
/>
这是个是IE8的专用标记,用来指定IE8浏览器去模拟某个特定版本的IE浏览器的渲染方式(比如人见人烦的IE6),以此来解决部分兼容问题,例如模拟IE7的具体方式如下:
<
meta
http-equiv
=
"X-UA-Compatible"
content
=
"IE=EmulateIE7"
/>
而上文提到的那个meta标记,则是在是安装了GCF后,用来指定页面使用chrome内核来渲染。
GCF下载地址: http://code.google.com/intl/zh-CN/chrome/chromeframe/
安装完成后,如果你想对某个页面使用GCF进行渲染,只需要在该页面的地址前加上 gcf: 即可,例如: gcf:http://cooleep.com
但是如果想要在开发时指定页面默认首先使用GCF进行渲染,如果未安装GCF再使用IE内核进行渲染,该如何进行呢?
就是使用这个标记。
标记用法
阅读了下chrome的开发文档(http://www.chromium.org/developers/how-tos/chrome-frame-getting-started,需翻墙),下面来简单讲解一下这个标记的语法。
1.最基本的用法:在页面的头部加入
<
meta
http-equiv
=
"X-UA-Compatible"
content
=
"chrome=1"
>
用以声明当前页面用chrome内核来渲染。
复杂一些的就是本文一开始看到的那中用法:
<
meta
http-equiv
=
"X-UA-Compatible"
content
=
"IE=edge,chrome=1"
/>
这样写可以达到的效果是如果安装了GCF,则使用GCF来渲染页面,如果为安装GCF,则使用最高版本的IE内核进行渲染。
2.通过修改HTTP头文件的方法来实现让指定的页面使用GCF内核进行渲染:
在HTTP的头文件中加入以下信息:X-UA-Compatible: chrome=1
在Apache服务器中,确保 mod_headers 和 mod_setenvif文件可用,然后在httpd.conf中加入以下配置信息:
<
IfModule
mod_setenvif.c>
<
IfModule
mod_headers.c>
BrowserMatch chromeframe gcf
Header append X-UA-Compatible "chrome=1" env=gcf
</
IfModule
>
</
IfModule
>
<
configuration
>
<
system.webServer
>
<
httpProtocol
>
<
customHeaders
>
<
add
name
=
"X-UA-Compatible"
value
=
"chrome=1"
/>
</
customHeaders
>
</
httpProtocol
>
</
system.webServer
>
</
configuration
>
找到\nginx\conf\nginx.conf并编辑,在server { }区域里(最好是闭合符前面起一行)添加下列代码即可
:
add_header "X-UA-Compatible" "IE=Edge, chrome=1";
=======================================================
在网站开发中不免因为各种兼容问题苦恼,针对兼容问题,其实IE给出了解决方案Google也给出了解决方案
百度也应用了这种方案去解决IE的兼容问题
百度源代码如下
<!Doctype html>
<html xmlns=http://www.w3.org/1999/xhtml xmlns:bd=http://www.baidu.com/2010/xbdml>
<head>
<meta http-equiv=Content-Type content=“text/html;charset=utf-8″>
<meta http-equiv=X-UA-Compatible content=IE=EmulateIE7>
<title>百度一下,你就知道 </title>
<script>var wpo={start:new Date*1,pid:109,page:‘superpage’}</script>
<meta http-equiv=X-UA-Compatible content=IE=EmulateIE7>
可以打开百度,右键查看源码看下!我们可以看下文件头是否存在这样一行代码!
这句话的意思是强制使用IE7模式来解析网页代码!
在这里送上几种IE使用模式!
<meta http-equiv=“X-UA-Compatible” content=“IE=8″>
2. Google Chrome Frame也可以让IE用上Chrome的引擎: <meta http-equiv=“X-UA-Compatible” content=“chrome=1″ />
3.强制IE8使用IE7模式来解析 <meta http-equiv=“X-UA-Compatible” content=“IE=EmulateIE7″><!– IE7 mode –>
//或者
<meta http-equiv=“X-UA-Compatible” content=“IE=7″><!– IE7 mode –>
4.强制IE8使用IE6或IE5模式来解析 :
<meta http-equiv=“X-UA-Compatible” content=“IE=6″><!– IE6 mode –>
<meta http-equiv=“X-UA-Compatible” content=“IE=5″><!– IE5 mode –>
5.如果一个特定版本的IE支持所要求的兼容性模式多于一种,如:
<meta http-equiv=“X-UA-Compatible” content=“IE=5; IE=8″ />
另外还有一起其他的解决方案,例如google的
ie7 – js中是一个JavaScript库(解决IE与W3C标准的冲突的JS库),使微软的Internet Explorer的行为像一个Web标准兼容的浏览器,支持更多的W3C标准,支持CSS2、CSS3选择器。它修复了许多的HTML和CSS问题,并使 得透明PNG在IE5、IE6下正确显示。
使IE5,IE6兼容到IE7模式(推荐)
<!–[if lt IE 7]>
<script src=”http://ie7-js.googlecode.com/svn/version/2.0(beta)/IE7.js” type=”text/javascript”></script>
<![endif]–>
使IE5,IE6,IE7兼容到IE8模式
<!–[if lt IE 8]>
<script src=”http://ie7-js.googlecode.com/svn/version/2.0(beta)/IE8.js” type=”text/javascript”></script>
<![endif]–>
使IE5,IE6,IE7,IE8兼容到IE9模式
<!–[if lt IE 9]>
<script src=”http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js”></script>
<![endif]–>
解决PNG显示问题
只需将透明png图片命名为*-trans.png
需要注意的是:此方法对背景平铺(background-repeat)和背景(background-position)无法起到任何作用,默认会占满整个容器。
--------------------===========================================----------------------------IE对文档的解析模式及兼容性问题
浏览器版本 | 结果 | 描述 |
Windows Store app或Windows UI中的浏览器 | IE 10 标准模式 | 这是Windows Store app和Windows UI中唯一支持的模式 |
Internet Explorer for the Desktop 或者 Internet Explorer 9 | IE9 标准模式 | 这正是x-ua-compatible指定的模式,而且浏览器支持这种模式 |
Internet Explorer 8 | IE8 标准模式 | 因为浏览器不支持IE9标准模式,所以使用浏览器支持的最高标准模式 |
Internet Explorer 7, Internet Explorer 6 或者 Internet Explorer 5.5 for mac | IE5 (Quirks)模式 | 这些浏览器不支持这个标签头,并且网页中也没有指定<!DOCTYPE> |
- 如果页面指定了DOCTYPE并且也使用了x-ua-compatible标签,则x-ua-compatible标签将覆盖DOCTYPE
- 如果浏览器支持x-ua-compatible标签,浏览器会使用他所支持的最高模式显示,则未必是标签指定的版本
- 对于不支持x-ua-compatible标签的老版本浏览器,使用<!DOCTYPE>来决定文档模式
- IE9和之前版本的浏览器,在遇到没有指定<!DOCTYPE>的页面时,使用IE5 Quirks模式解析文档,所以建议所有文档都要包含<!DOCTYPE>