bootstrap兼容IE8,IE7

今天需要調整頁面兼容IE7

學習了:http://www.lxway.com/444544602.htm 

百度了下

<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

前者定義媒體查詢,後者確定顯示此網頁的IE版本

<meta name="viewport" content="width=device-width,initial-scale=1" >

<meta name="renderer" content="webkit">
<meta name="renderer" content="ie-stand">

<meta name=”renderer” content=”webkit|ie-comp|ie-stand” />

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

<!-- JS -->
<script type="text/javascript" src="${contextPath}/static/jquery/jquery-2.1.4.min.js"></script>
<!--[if lte IE 8]>
<script src="${contextPath}/static/respond.min.js"></script>
<script src="${contextPath}/static/html5shiv.js"></script>
<script type="text/javascript" src="${contextPath}/static/jquery/jquery-1.11.3.min.js"></script>
<![endif]-->

引入respond.js 和 html5.js

respond.jsGithub)是用於媒體查詢的,項目說明描述:要和需要進行媒體查詢的文件放在同一域中。不然CDN部署的需要更改一些選項,之後再說。

html5shiv : html5.js(Google Code)(Github)是讓不(完全)支持html5的瀏覽器“支持”html5標籤。

<!--[if lte IE 9]>
<script src="bootstrap/js/respond.min.js"></script>
<script src="bootstrap/js/html5.js"></script>
<![endif]-->
Jquery 2.0以上就不再支持IE 6/7/8 這三大虐心神器了。所以要想使用Bootstrap3中的一些插件效果,比如modal 彈出層對話框這類控件。我們就需要添加 2.0以下的,這裏我用1.10.2的Jquery庫。

CSS文件在CDN上(或子域名)的Respond.js部署

詳情請見:https://github.com/scottjehl/Respond#cdnx-domain-setup

Github上說,這個js是通過ajax一份你的css文件。所以需要一個代理頁面去請求文件。

需要上傳一些文件,步驟比較複雜,而且一般公共CDN基本沒人有這種操作權限。

之後再添加代碼。

 <!-- Respond.js proxy on external server -->
<link href="http://externalcdn.com/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />

<!-- Respond.js redirect location on local server -->
<link href="/path/to/respond.proxy.gif" id="respond-redirect" rel="respond-redirect" />

<!-- Respond.js proxy script on local server -->
<script src="/path/to/respond.proxy.js"></script>

本人也正是做了個Bootstrap3的小項目(姓名代碼查詢,由於使用CDN,E8有短暫屏閃,且屏閃無法避免),正是這個項目讓我總結以上經驗出來。

主要還是在於讓respond.js起效果,關鍵就是讓bootstrap的文件和respond.js同域,不同域需要用CDN上的html做ajax。

<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="author" content="Jophy" />
    <title>ie8</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="bootstrap/css/style.css">
    <!--[if lte IE 9]>
    <script src="bootstrap/js/respond.min.js"></script>
    <script src="bootstrap/js/html5.js"></script>
    <![endif]-->
    <script src="http://libs.baidu.com/jquery/1.10.2/jquery.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
</body>
</html>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章