兼容ie8(WebUploader+class+prototype)

633 阅读1分钟
最近公司有个jq写的老项目(手动微笑),要兼容ie8,出现了些问题

1.样式丑

用hack\9直接写ie8的样式

2.js的trim,indexOf报错

用prototype新写了方法

if (!Array.prototype.indexOf){
    Array.prototype.indexOf = function(elt){
        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
    }
}
if (!String.prototype.trim){
    String.prototype.trim = function(elt){
        return $.trim(this)
    }
}

3.还有个本地请求不行

原来是ie8不支持跨域,因为我设置的是nginx反向代理请求用的cors
似乎设置一下ie就能跨,但是我一想,发到线上是不用跨域的,所以就没去管

WebUploader1.6.0报错

报错大概是第二个红箭头位置
第一个红箭头,监视出来是 [html5, flash]
查了一下,WebUploader1有html5和flash俩种模式,ie8肯定不支持html5的

1.首先加一个
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
2.然后网上下了Uploader.swf, 找到调用方法的地方(也就是我们开发者自己的配置js),把flash路径写对,
再往ie上安装了flash。就ok了
 var uploader = WebUploader.create({
    auto: true,// 选完文件后,是否自动上传。
    // swf文件路径
    swf: '../../js/plugin/webuploader/Uploader.swf',
    paste: document.body,

    // 文件接收服务端。
    server: serverUrl+"files/upload",
    formData:postData,
    ...

说起来很简单啊,但是实践的时候一条条办法也是很辛苦的啦