流动:
- 将 XHR 与 CORS 一起使用以将图像文件作为 Blob
- 从响应中创建 Blob 对象
- 到目前为止 - 一切正常
- 使用 createObjectURL 来初始化 Image 对象
- “onload”事件永远不会触发,“onerror”事件总是会触发错误。
例子:
var blob = new Blob(...);
var img = document.createElement('img');
img.onload = function (e1) {
//do something after image loaded
};
img.onerror = function(e2) {
alert('Error!');
//always fires on Safari
};
img.src = my_createObjectURL(blob);
document.body.appendChild(img);
function my_createObjectURL(blob) {
if (window.webkitURL) {
return window.webkitURL.createObjectURL(blob);
}
else if (window.URL && window.URL.createObjectURL) {
return window.URL.createObjectURL(blob);
}
else {
return null;
}
}
Firefox、Chrome 和 IE10——正常工作,没有错误
在 Safari 6.0.5 上测试——永远不会加载,总是会收到 onerror 事件