ie8兼容及部分总结

哈哈哈
• 阅读 1012

兼容

  1. 兼容promise :引入bluebird.js

  2. 兼容媒体查询和layui栅格布局:引入html5shiv.js 和respond.js

  3. 兼容console。ie8正式环境下console未定义,如果打包没有去掉console,会堵塞代码

    (function () {
     var method;
     var noop = function () { };
     var methods = [
         'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
         'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
         'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
         'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
     ];
     var length = methods.length;
     var console = (window.console = window.console || {});
    
     while (length--) {
         method = methods[length];
    
         // Only stub undefined methods.
         if (!console[method]) {
             console[method] = noop;
         }
     }
    }());
  4. 判断ie版本

    function IEVersion() {
     var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串  
     var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器  
     var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
     var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
     if (isIE) {
         var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
         reIE.test(userAgent);
         var fIEVersion = parseFloat(RegExp["$1"]);
         if (fIEVersion == 7) {
             return 7;
         } else if (fIEVersion == 8) {
             return 8;
         } else if (fIEVersion == 9) {
             return 9;
         } else if (fIEVersion == 10) {
             return 10;
         } else {
             return 6; //IE版本<=7
         }
     } else if (isEdge) {
         return 'edge'; //edge
     } else if (isIE11) {
         return 11; //IE11  
     } else {
         return -1; //不是ie浏览器
     }
    };
  5. 兼容forEach

    ! function () {
     if (!Array.prototype.forEach) {
         Array.prototype.forEach = function (callback /*, thisArg*/) {
             var T, k;
             if (this == null) {
                 throw new TypeError('this is null or not defined');
             }
             var O = Object(this);
             var len = O.length >>> 0;
             if (typeof callback !== 'function') {
                 throw new TypeError(callback + ' is not a function');
             }
             if (arguments.length > 1) {
                 T = arguments[1];
             }
             k = 0;
             while (k < len) {
                 var kValue;
                 if (k in O) {
                     kValue = O[k];
                     callback.call(T, kValue, k, O);
                 }
                 k++;
             }
         };
     }
    }();
  6. 兼容indexOf()

    if (!Array.prototype.indexOf) {
     Array.prototype.indexOf = function (elt /*, from*/) {
         var len = this.length >>> 0;
         var from = Number(arguments[1]) || 0;
         from = (from < 0) ? Math.ceil(from) : Math.floor(from);
         if (from < 0)
             from += len;
         for (; from < len; from++) {
             if (from in this &&
                 this[from] === elt)
                 return from;
         }
         return -1;
     };
    }
  7. 兼容opacity:filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.3)

  8. 兼容圆角 引入PIE.htc

    x{
    -moz-border-radius: 15px;
    -webkit-border-radius: 15px;
    border-radius: 15px;
    behavior: url(./PIE.htc);//文件必须和html同级
    position: relative;
    }

问题

  1. 数组结尾不能有逗号,ie8中循环会生成一项empty

下载

  • ie8只能让后端返回文件地址,window.open(地址),a标签,window.location.href='地址',下载
  • ie10及以上;后端返回文件流,可以使用blob下载

有的问题没有记录,像es6,html5的部分东西直接不用就行

点赞
收藏
评论区
推荐文章

暂无数据

哈哈哈
哈哈哈
Lv1
能够慢慢培养的不是感情而是习惯
文章
1
粉丝
3
获赞
6
热门文章