一行代碼解決各種IE兼容問題,IE6,IE7,IE8,IE9,IE10

一行代碼解決各種IE兼容問題,IE6,IE7,IE8,IE9,IE10在網站開發中不免因爲各種兼容問題苦惱,針對兼容問題,其實IE給出瞭解決方案Google也給出瞭解決方案百度也應用了這種方案去解決IE的兼容問題百度源代碼如下<!Doctype...

一行代碼解決各種IE兼容問題,IE6,IE7,IE8,IE9,IE10

在網站開發中不免因爲各種兼容問題苦惱,針對兼容問題,其實IE給出瞭解決方案Google也給出瞭解決方案

百度也應用了這種方案去解決IE的兼容問題

百度源代碼如下

  1. <!Doctype html>
  2. <htmlxmlns=http://www.w3.org/1999/xhtmlxmlns:bd=http://www.baidu.com/2010/xbdml>
  3. <head>
  4. <metahttp-equiv=Content-Typecontent=“text/html;charset=utf-8″>
  5. <metahttp-equiv=X-UA-Compatiblecontent=IE=EmulateIE7>
  6. <title>百度一下,你就知道 </title>
  7. <script>var wpo={start:newDate*1,pid:109,page:‘superpage’}</script>

<meta http-equiv=X-UA-Compatible content=IE=EmulateIE7>

可以打開百度,右鍵查看源碼看下!我們可以看下文件頭是否存在這樣一行代碼!

這句話的意思是強制使用IE7模式來解析網頁代碼!

然而同樣的解決方案在一些大型的電子商務網站也很多見China Wholesale Electronics

從源碼中我們可以看到

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>Home page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Online shopping for cool gadgets at the right price. Buy cheap computers, electronics, car accessories, cellphones, iPhone, apparels and home gadgets on, free shipping for all orders." />
<meta name="keywords" content="cool gadgets, free shipping" />
<meta name="robots" content="INDEX,FOLLOW" />

在這裏送上幾種IE使用模式!

  1. <metahttp-equiv=“X-UA-Compatible”content=“IE=8″>

2. Google Chrome Frame也可以讓IE用上Chrome的引擎:

  1. <metahttp-equiv=“X-UA-Compatible”content=“chrome=1″/>

3.強制IE8使用IE7模式來解析

  1. <metahttp-equiv=“X-UA-Compatible”content=“IE=EmulateIE7″><!– IE7 mode –>
  2. //或者
  3. <metahttp-equiv=“X-UA-Compatible”content=“IE=7″><!– IE7 mode –>

4.強制IE8使用IE6或IE5模式來解析

  1. <metahttp-equiv=“X-UA-Compatible”content=“IE=6″><!– IE6 mode –>

  2. <metahttp-equiv=“X-UA-Compatible”content=“IE=5″><!– IE5 mode –>

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

  1. <metahttp-equiv=“X-UA-Compatible”content=“IE=5; IE=8″/>

二.設定網站服務器以指定預設兼容性模式

如果服務器是自己的話,可以在服務器上定義一個自訂標頭來爲它們的網站預設一個特定的文件兼容性模式。這個特定的方法取決於你的網站服務器。

錄入,下列的 web.config文件使Microsoft Internet Information Services (IIS)能定義一個自訂標頭以自動使用IE7 mode來編譯所有網頁。

另外還有一起其他的解決方案,例如google的

ie7 – js中是一個JavaScript庫(解決IE與W3C標準的衝突的JS庫),使微軟的Internet Explorer的行爲像一個Web標準兼容的瀏覽器,支持更多的W3C標準,支持CSS2、CSS3選擇器。它修復了許多的HTML和CSS問題,並使得透明PNG在IE5、IE6下正確顯示。

使IE5,IE6兼容到IE7模式(推薦)

  1. <!–[if lt IE 7]>
  2. <script src=”http://ie7-js.googlecode.com/svn/version/2.0(beta)/IE7.js” type=”text/javascript”></script>
  3. <![endif]–>

使IE5,IE6,IE7兼容到IE8模式

  1. <!–[if lt IE 8]>
  2. <script src=”http://ie7-js.googlecode.com/svn/version/2.0(beta)/IE8.js” type=”text/javascript”></script>
  3. <![endif]–>

使IE5,IE6,IE7,IE8兼容到IE9模式

  1. <!–[if lt IE 9]>
  2. <script src=”http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js”></script>
  3. <![endif]–>

解決PNG顯示問題

只需將透明png圖片命名爲*-trans.png

需要注意的是:此方法對背景平鋪(background-repeat)和背景(background-position)無法起到任何作用,默認會佔滿整個容器

看完本文希望你的IE6,IE7,IE8,IE9,IE10等等兼容問題可以得到解決!


發佈了7 篇原創文章 · 獲贊 0 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章