設置IE兼容模式的幾種方法

一.指定文件兼容性模式
要爲你的網頁指定文件模式,須要在你的網頁中使用meta元素放入x-ua-compatible http-equiv 標頭。
1. 強制ie8使用ie8模式來解析,並且那個兼容性視圖按鈕也被去掉了web

<meta http-equiv="x-ua-compatible" content="ie=8"/>

 

2. google chrome frame也可讓ie用上chrome的引擎:chrome

<meta http-equiv="x-ua-compatible" content="chrome=1" />

 

3.強制ie8使用ie7模式來解析服務器

<meta http-equiv="x-ua-compatible" content="ie=emulateie7"><!-- ie7 mode --> 
或者
<meta http-equiv="x-ua-compatible" content="ie=7"><!-- ie7 mode -->

 

4.強制ie8使用ie6或ie5模式來解析網站

<meta http-equiv="x-ua-compatible" content="ie=6"><!-- ie6 mode -->   
<meta http-equiv="x-ua-compatible" content="ie=5"><!-- ie5 mode --> 

 

5.若是一個特定版本的ie支持所要求的兼容性模式多於一種,如:ui

<meta http-equiv="x-ua-compatible" content="ie=5; ie=8" />

 

二.設定網站服務器以指定預設兼容性模式
網站管理員可籍着爲網站定義一個自訂標頭來爲他們的網站預設一個特定的文件兼容性模式。這個特定的方法取決於你的網站服務器。舉例來講,下列的 web.config文件使microsoft internet information services (iis)能定義一個自訂標頭以自動使用ie7 mode來編譯全部網頁。google

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
  <httpProtocol>
   <customHeaders>
    <clear/>
    <add name="x-ua-compatible" value="ie=emulateie7" />
   </customHeaders>
  </httpProtocol>
 </system.webServer></configuration> 

若你已於網站服務器指定了一個預設的文件兼容性模式,你能夠在個別頁面上指定不一樣的文件兼容性模式來蓋過它。在網頁中指定的模式優先權高於服務器中所指定的模式。spa

原文:http://blog.csdn.net/gaozhigang/article/details/7804566.net

相關文章
相關標籤/搜索