IE ToDataUrl() Security Error
I need to get my picture from canvas, so I get my image from Amazon S3, I have enabled Cross-Origin Resource Sharing (CORS) there and I have set croseOrigin attribute 'anonymous' t
Solution 1:
I fixed this security error in IE 11 by using fabric js. By npm install fabric or CDN.
var fabriclib = require("fabric");
var svg = document.querySelector('svg');
var width = $('#chart-container').find('svg').width();
var height = $('#chart-container').find('svg').height();
var DOMURL = window.URL || window.webkitURL || window;
var data = (new XMLSerializer()).serializeToString(svg);
data = data.replace(/xmlns=\"http:\/\/www\.w3\.org\/2000\/svg\"/, '');
var img = new Image();
var svgBlob = new Blob([data], {type: 'image/svg+xml;charset=utf-8'});
var url = DOMURL.createObjectURL(svgBlob);
img.onload = function () {
var canvas = new fabriclib.fabric.Canvas();
var svgStr = data;
fabriclib.fabric.loadSVGFromString(svgStr, function(objects, options){
var object = fabriclib.fabric.util.groupSVGElements(objects, options);
canvas.add(object);
var ctx = canvas.getContext('2d');
ctx.canvas.width = width;
ctx.canvas.height = height;
fabriclib.fabric.util.loadImage(svgStr, function(img) {
ctx.drawImage(img, 0, 0, width, height);
img.crossOrigin = "Anonymous";
}, {
crossOrigin: 'anonymous'
});
DOMURL.revokeObjectURL(url);
var dataUrl = canvas.toDataURL({format: "png"});
});
}
img.src = url;
Solution 2:
I'm not sure if it's the best way, but i have found a solution for this. Just converting the img to base64, and no error. This helped -> how to convert to base64
Post a Comment for "IE ToDataUrl() Security Error"