IE7兼容模式与兼容视图

作者:sohighthesky 来源:博客园 时间:2010-06-28 18:48:00 

阅读之前:

在看文章具体内容之前,希望你可以 先打开IE8,打开http://www.taobao.com,然后在地址栏里输入:

javascript:alert(document.documentMode +navigator.userAgent);void(0)

看到结果后不知道你有没觉得惊奇,反正我是觉得很奇怪的,因为页面meta里没有兼容标记, fiddler查看 http头里也没有X-UA-Compatible标记,网站到底为什么会运行在ie7模式下呢?

IE7兼容模式 与 兼容视图

昨天在看口碑的一篇 iframe高度自适应 时,发现它给的demo与我本的demo在ie8中运行结果不一样,在线的结果明显跟在IETester7中一样,也查看 过,meta里没有兼容标记, fiddler查看 http头里也没有X-UA-Compatible标记,可是为什么在线的结果与本地的会不一样呢?这样我就郁闷了,再一看,发现在线demo在IE8中没有显示“兼容视图”按钮,想想肯定是这个的原因.

后来找到一篇文章  Just The Facts: Recap of Compatibility View 虽然没解决问题,但内容不错,分享一下,引用其中一段话:

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 <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 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.

意思是说,兼容视图起三个作用:

  1. UserAgent

  2. 版本标识(包括条件注释)

  3. 文档 类型

而meta标记只起两个作用:1.版本,2.文档 类型

(这里说meta标记不影响UserAgent应该是指服务端的ua,因为客户端请求已经发送,并且包含了ua,所以不会影响 ,不过客户端的ua还是受影响 了,显示ie7 )

更正:

(可能之前测试有误)客户端的ua也不影响 ,只会影响document.documentMode

另外:

 <META> tag / header分别 指:<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">和在服务端添加http头,比如.net配置文件中:


<configuration>
    <system.webServer>
        <httpProtocol>
            <customHeaders>
                <clear />
                <add name="X-UA-Compatible" value="IE=EmulateIE7" />
            </customHeaders>
        </httpProtocol>
    </system.webServer>
</configuration> 


另外也可以到IIS或者 Apache中添加http头:

  1. Implementing the META Switch on Apache

  2. Implementing the META Switch on IIS

问题解决

到这里了文章开始的问题还是没有解决,昨晚无意间看到秦歌的一篇用doctype激活浏览器模式,中提到 微软的黑名单站点列表中也会启用兼容模式,记得上面那文章第二条评论中有一个:res://iecompat.dll/iecompatdata.xml(IE8 only哦),将这个地址输入到ie8中会显示:Compatibility View list,这样在这个列表中终于找到口碑和淘宝的域名,于是我想这应该就是本文开始时问题的答案了,你也可以在这个列表中随便找一个域名,打开,在地址栏输入文章开始那那段javascript(ps:微软这个列表也太多了吧,将这么多站点弄成IE7。。)

其它参考链接:

Defining Document Compatibility

标签:ie7,兼容模式,兼容视图,浏览器
0
投稿

猜你喜欢

  • 数据库基础:MySQL 添加用户的两种方法

    2009-05-07 14:26:00
  • 用ASP设计购物车

    2008-04-17 13:52:00
  • “)”引起PNG透明滤镜失效

    2008-08-11 13:10:00
  • Opera下cloneNode的bug

    2007-11-23 11:40:00
  • 怎样管理好css样式

    2008-10-12 12:12:00
  • asp如何用CDONTS发送带附件的邮件?

    2010-06-11 19:57:00
  • 一个CSS图片切换效果代码

    2008-02-12 12:17:00
  • asp截取字符串的两种应用

    2009-08-19 17:11:00
  • iframe 的用法与注意事项

    2008-02-12 12:56:00
  • 交互设计实用指南系列(5) – 突出重点,一目了然

    2010-01-11 21:05:00
  • sql如何实现复合查询?

    2010-05-19 21:25:00
  • ORACLE常见错误代码的分析与解决三

    2010-07-26 13:28:00
  • 给网站界面预留退路

    2009-03-25 20:32:00
  • 设计从"心"开始

    2011-05-21 08:37:00
  • 有用的SQL语句(删除重复记录,收缩日志)

    2008-03-04 16:59:00
  • Mootools 1.2教程(22)——同时进行多个形变动画

    2008-12-29 14:11:00
  • 悟道Web标准:让W3C标准兼容终端

    2009-10-11 16:40:00
  • IE6下的CSS BUG枚举

    2010-06-11 10:45:00
  • 写了一个小巧的jquery拾色工具

    2009-12-21 14:22:00
  • 一个很棒的js图片代码

    2009-12-17 18:36:00
  • asp之家 网络编程 m.aspxhome.com