jquery ie11 html函数,html - JavaScript readAsBinaryString Function on E11 - Stack Overflow

I had some problems with the answers here and ended up making a few slight changes.

Instead of assigning to pt.content, my solution is to send a custom object to the prototype's onload, that receiver can specifically look for, I named this property msieContent so it will be very specific.

Also I used other accepted answer for converting Uint8Array to string in more robust way, you can see full details of it here:

https://stackoverflow.com/a/12713326/213050

Polyfill

if (FileReader.prototype.readAsBinaryString === undefined) {

// https://stackoverflow.com/a/12713326/213050

function Uint8ToString(u8a: Uint8Array) {

const CHUNK_SZ = 0x8000;

let c = [];

for (let i = 0; i < u8a.length; i += CHUNK_SZ) {

c.push(String.fromCharCode.apply(null, u8a.subarray(i, i + CHUNK_SZ)));

}

return c.join('');

}

FileReader.prototype.readAsBinaryString = function (fileData) {

const reader = new FileReader();

reader.onload = () => this.onload({

msieContent: Uint8ToString(new Uint8Array(reader.result))

});

reader.readAsArrayBuffer(fileData);

}

}

Usage

private _handleTextFile(file: File) {

const reader = new FileReader();

reader.onload = (e) => {

// support for msie, see polyfills.ts

const readResult: string = (e).msieContent || e.target.result;

};

reader.readAsBinaryString(file);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值