base 图片解码 window.atob() ie9 以下 未定义 解决 IE9 ie8
function base64Img2Blob(code){
var parts = code.split(';base64,');
var contentType = parts[0].split(':')[1];
var raw = window.atob(parts[1]);
var rawLength = raw.length;
var uInt8Array = new Uint8Array(rawLength);
for (var i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new Blob([uInt8Array], {type: contentType});
}`
IE8中js不支持得太多了,你如果只是要做base64解码然后显示图片,不如用flex/flash之类的插件做。
自己用js写一个atob实现,好像网站有现成的,你找找看。
引入兼容库jQuery.base64.js。
if (!window.btoa) window.btoa = $.base64.btoa;
if (!window.atob) window.atob = $.base64.atob;
不过我估计代码里的Uint8Array、Blob也是不兼容的。