一. 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
精华摘抄:
?We’ve evangelized use of the X-UA-Compatible tag to websites unable to update to support IE8’s Standards mode. The tag allows a web author to declare the exact standards mode behavior for which their website works best – IE8 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”.
?We’ve 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 haven’t 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 to – IE8 Standards or IE7 Standards. The X-UA-Compatible 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 can’t affect the UA string as it’s already too late to change that – the client’s 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) won’t make your website compatible – you’ll also need to update your User Agent string detection logic as well.
推荐阅读
- 怎么完美解决IE8下不兼容rgba的问题?解决的方法分享
- win7怎么卸载ie10?WIN7卸载IE10恢复到IE8或者是IE9图文教程分享
- xp系统ie8浏览器经常崩溃或无响应怎么解决?解决xp下ie8崩溃或无响应的解决方法图文教程分享
- IE8浏览器点击后退没反应该怎样解决?解决的方法介绍
- Win7怎么卸载IE10浏览器?想恢复到IE8或者是IE9怎么办?
- xp系统ie8浏览器经常崩溃或无响应怎么办?xp下ie8崩溃或无响应的解决方法图文教程分
- IE8中禁止访问Https网站弹出窗口出现的妙招
- 使用IE8几个私密技巧
- 在IE8中享受IE9的隐藏搜索栏功能
- 从IE9回到IE8的技巧