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
投稿

猜你喜欢

  • Python 数据科学 Matplotlib图库详解

    2022-09-24 15:18:34
  • 通过数据库对Django进行删除字段和删除模型的操作

    2024-01-19 09:28:44
  • Python encode()方法和decode()方法详解

    2023-06-16 11:47:15
  • Go语言对字符串进行MD5加密的方法

    2024-05-09 14:54:38
  • 用asp给网站添加rss聚合功能

    2007-11-05 19:08:00
  • mysql的in会不会让索引失效?

    2024-01-27 11:50:44
  • 使用beaker让Facebook的Bottle框架支持session功能

    2023-07-01 02:35:35
  • Python入门教程之Python的安装下载配置

    2021-08-18 06:01:14
  • javascript实现简单的可随机变色网页计算器示例

    2024-04-16 09:37:07
  • 细化解析:Mysql数据库对文件操作的封装

    2008-11-27 16:32:00
  • 通过Py2exe将自己的python程序打包成.exe/.app的方法

    2021-07-05 11:05:55
  • 略谈美国雅虎首页改版

    2009-07-26 18:34:00
  • python 用递归实现通用爬虫解析器

    2022-04-15 08:13:55
  • window.showModalDialog()返回值的学习心得总结

    2024-05-09 10:35:39
  • Python 中Operator模块的使用

    2021-04-02 05:30:34
  • python通过urllib2获取带有中文参数url内容的方法

    2022-07-26 10:35:58
  • Django项目实战之用户头像上传与访问的示例

    2021-01-27 04:28:16
  • 多个函数验证同一表单方法

    2007-10-06 22:55:00
  • php验证码的制作思路和实现方法

    2023-09-04 13:23:37
  • python中startswith()和endswith()的用法详解

    2023-11-02 12:41:09
  • asp之家 网络编程 m.aspxhome.com