IE7 mode IE8兼容视图与独立IE7的区别详解

【IE7 mode IE8兼容视图与独立IE7的区别详解】一. IE8兼容视图概述
为了解决新版浏览器不兼容旧网站的问题,IE8浏览器增加了一种叫做兼容性视图的功能,可以让网页以IE7的代码规范来显示,这样,就能够很好的解决大部分(但不是全部)由于代码标准不一致引起的网页问题 。
二.浏览器模式和文档模式之间的区别
兼容性视图涉及两个重要的功能便是浏览器模式browser mode和文档模式document mode,在IE8中按F12键,打开开发人员工具,在菜单栏中可以看到浏览器模式和文档模式的切换菜单,其中可以选择切换到IE7/8等不同的网页模式 。
那浏览器模式和文档模式之间有什么区别呢?
浏览器模式用于切换IE针对该网页的默认文档模式、对不同版本浏览器的条件备注解析、发送给网站服务器的用户代理(User-Agent)字符串的值 。网站可以根据浏览器返回的不同用户代理字符串判断浏览器的版本和安装的功能,这样就可以向不同的浏览器返回不同的页面内容 。
默认情况下,IE8的浏览器模式为IE8 。用户可以通过单击地址栏旁边的兼容性视图按钮来手动切换到不同的浏览器模式 。在IE8中,IE8兼容性视图会以IE7文档模式来显示网页,同时会向服务器发送IE7的用户代理字符串 。
文档模式用于指定IE的页面排版引擎(Trident)以哪个版本的方式来解析并渲染网页代码 。切换文档模式会导致网页被刷新,但不会更改用户代理字符串中的版本号,也不会从服务器重新下载网页 。切换浏览器模式的同时,浏览器也会自动切换到相应的文档模式 。
一般来说,两者都要设置为同样的版本,但是,如果不同又如何呢?或者说两者是否有优先级区别呢?
请看下面的msdn帖子:Just The Facts: Recap of Compatibility View
http://blogs.msdn.com/b/ie/archive/2009/02/16/just-the-facts-recap-of-compatibility-view.aspx
精华摘抄:
Weve evangelized use of the X-UA-Compatible tag to websites unable to update to support IE8s Standards mode. The tag allows a web author to declare the exact standards mode behavior for which their website works bestIE8 Standards (again, the default when no header is present) or IE7 Standards. For example, using the value IE=EmulateIE7 causes IE8 to display a website as IE7 would have.
Weve provided end-user and corporate / IT mitigations to the website compatibility problem under the umbrella term Compatibility View. Compatibility View allows IE8 users to have a great experience even when visiting websites that havent yet performed either of the above two steps. It also helps IT organizations preserve compatibility with the large number of line-of-business websites that are Internet Explorer 7 capable today.
Compatibility View and the X-UA-Compatible tag are not equivalent. Compatibility View is something you do on the client. It affects three things: the User Agent string, the Version Vector (used in evaluation of conditional comments), and what mode DOCTYPEs that trigger Standards map toIE8 Standards or IE7 Standards. The X-UA-Compatible META tag / header is something you use in page content / server-side and, when present, completely overrides Compatibility View settings on the client. It affects two things: the Version Vector and what mode DOCTYPEs that trigger Standards map to. It cant affect the UA string as its already too late to change thatthe clients already made the GET request to the server (and it contains a UA string). What this means to developers is that if your site pivots on the User Agent string, adding just the X-UA-Compatible tag (to cause IE8 to display your site in IE7 Standards mode) wont make your website compatibleyoull also need to update your User Agent string detection logic as well.
总结,有两种方式可以使IE8兼容IE7模式,一是在服务器端,通过程序员控制修改网页的文档模式document mode,也就是通过Meta(X-UA-Compatible IE=EmulateIE7), 强制使页面变为兼容IE7的页面 。

推荐阅读