解决IE不支持html5 file api中readAsBinaryString

解决IE不支持html5 file api中readAsBinaryString

坑爹的IE啊,不过还是有办法的。重写readAsBinaryString,用IE支持的方式


FileReader.prototype.readAsBinaryString = function (fileData) {
       var binary = "";
       var pt = this;
       var reader = new FileReader();      
       reader.onload = function (e) {
           var bytes = new Uint8Array(reader.result);
           var length = bytes.byteLength;
           for (var i = 0; i < length; i++) {
               binary += String.fromCharCode(bytes[i]);
           }
        //pt.result  - readonly so assign binary
        pt.content = binary;
        $(pt).trigger('onload');
    }

转载自:http://www.godeye.org/share/detail/18

你可能感兴趣的:(godeye)