閱讀之前:
在看文章具體內(nèi)容之前,希望你可以 先打開IE8,打開http://www.taobao.com,然后在地址欄里輸入:
javascript:alert(document.documentMode +navigator.userAgent);void(0)
看到結(jié)果后不知道你有沒覺得驚奇,反正我是覺得很奇怪的,因?yàn)轫撁鎚eta里沒有兼容標(biāo)記, fiddler查看 http頭里也沒有X-UA-Compatible標(biāo)記,網(wǎng)站到底為什么會運(yùn)行在ie7模式下呢?
IE7兼容模式 與 兼容視圖
昨天在看口碑的一篇 iframe高度自適應(yīng) 時,發(fā)現(xiàn)它給的demo與我本的demo在ie8中運(yùn)行結(jié)果不一樣,在線的結(jié)果明顯跟在IETester7中一樣,也查看 過,meta里沒有兼容標(biāo)記, fiddler查看 http頭里也沒有X-UA-Compatible標(biāo)記,可是為什么在線的結(jié)果與本地的會不一樣呢?這樣我就郁悶了,再一看,發(fā)現(xiàn)在線demo在IE8中沒有顯示“兼容視圖”按鈕,想想肯定是這個的原因.
后來找到一篇文章 Just The Facts: Recap of Compatibility View 雖然沒解決問題,但內(nèi)容不錯,分享一下,引用其中一段話:
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.
意思是說,兼容視圖起三個作用:
- UserAgent
- 版本標(biāo)識(包括條件注釋)
- 文檔 類型
而meta標(biāo)記只起兩個作用:1.版本,2.文檔 類型
(這里說meta標(biāo)記不影響UserAgent應(yīng)該是指服務(wù)端的ua,因?yàn)榭蛻舳苏埱笠呀?jīng)發(fā)送,并且包含了ua,所以不會影響 ,不過客戶端的ua還是受影響 了,顯示ie7 )
更正:
(可能之前測試有誤)客戶端的ua也不影響 ,只會影響document.documentMode
另外:
<META> tag / header分別 指:<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">和在服務(wù)端添加http頭,比如.net配置文件中:
<configuration> <system.webServer> <httpProtocol> <customHeaders> <clear /> <add name="X-UA-Compatible" value="IE=EmulateIE7" /> </customHeaders> </httpProtocol> </system.webServer> </configuration>
另外也可以到IIS或者 Apache中添加http頭:
- Implementing the META Switch on Apache
- Implementing the META Switch on IIS
問題解決
到這里了文章開始的問題還是沒有解決,昨晚無意間看到秦歌的一篇用doctype激活瀏覽器模式,中提到 微軟的黑名單站點(diǎn)列表中也會啟用兼容模式,記得上面那文章第二條評論中有一個:res://iecompat.dll/iecompatdata.xml(IE8 only哦),將這個地址輸入到ie8中會顯示:Compatibility View list,這樣在這個列表中終于找到口碑和淘寶的域名,于是我想這應(yīng)該就是本文開始時問題的答案了,你也可以在這個列表中隨便找一個域名,打開,在地址欄輸入文章開始那那段javascript(ps:微軟這個列表也太多了吧,將這么多站點(diǎn)弄成IE7。。)
其它參考鏈接:
Defining Document Compatibility
本文鏈接:http://m.95time.cn/tech/web/2010/7744.asp
出處:博客園
責(zé)任編輯:bluehearts
◎進(jìn)入論壇網(wǎng)頁制作、WEB標(biāo)準(zhǔn)化版塊參加討論,我還想發(fā)表評論。
|