I have svg content and I want to draw this svg on canvas.Then I want dataURL of canvas but IE
gives error of SecurityError
.I have spent whole day but i didn't get right thing.Below is code that I have done so far.
var canvas = document.getElementById("canvas");
canvas.setAttribute("height", 500);
canvas.setAttribute("width", 500);
var ctx = canvas.getContext("2d");
var DOMURL = self.URL || self.webkitURL || self;
var img = new Image();
var svg = new Blob([svgString], { type: "image/svg+xml;charset=utf-8" });
var url = DOMURL.createObjectURL(svg);
img.onload = function () {
ctx.drawImage(img, 0, 0);
var image = canvas.toDataURL('image/png');
};
img.onerror = function () {
};
img.src = url;
On above code everything works fine in mozilla and chrome but IE gives an error on canvas.toDataURL
. How can I fix this?? Please help me and thanks in advance.