兼容IE浏览器对象不支持toBlob属性或方法问题

dep_wangsr
RuoYi 4 years ago committed by Limy
parent 681511d418
commit e80a2ad126

@ -214,29 +214,48 @@ $(window).load(function() {
}); });
function submitHandler() { function submitHandler() {
if(!croppable){ if (!croppable) {
$.modal.alertWarning("裁剪框加载中,请稍后..."); $.modal.alertWarning("裁剪框加载中,请稍后...");
return return
} }
cropper.getCroppedCanvas().toBlob(function(img){ cropper.getCroppedCanvas().toBlob(function(img) {
var formdata = new FormData(); var formdata = new FormData();
formdata.append("avatarfile", img); formdata.append("avatarfile", img);
$.ajax({ $.ajax({
url: ctx + "system/user/profile/updateAvatar", url: ctx + "system/user/profile/updateAvatar",
data: formdata, data: formdata,
type: "post", type: "post",
processData: false, processData: false,
contentType: false, contentType: false,
success: function(result) { success: function(result) {
$.operate.saveSuccess(result); $.operate.saveSuccess(result);
} }
}) })
}); });
} }
$(window).resize(function(){ $(window).resize(function() {
$('.imageBox').height($(window).height()-80); $('.imageBox').height($(window).height() - 80);
}).resize(); }).resize();
if (!HTMLCanvasElement.prototype.toBlob) {
Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
value: function(callback, type, quality) {
var canvas = this;
setTimeout(function() {
var binStr = atob(canvas.toDataURL(type, quality).split(',')[1]);
var len = binStr.length;
var arr = new Uint8Array(len);
for (var i = 0; i < len; i++) {
arr[i] = binStr.charCodeAt(i);
}
callback(new Blob([arr], {
type: type || 'image/png'
}));
});
}
});
}
</script> </script>
</body> </body>
</html> </html>

Loading…
Cancel
Save