我有一个高图(svg)我试图将其转换为图像base64格式。在Chrome中它在IE11中正常工作(抛出安全性错误)
highchartsExport.nativeSVGtoImage($("#highchartcontainer").find("svg")[0],function(uri){
var data = $.param({'dataURL': uri, 'emailContent': $scope.content});
var config = {headers: {'Content-Type': 'application/pdf;'}}
在highchartsExport中:
exp.nativeSVGtoImage = function(DOMObject,callback,format){
if(!DOMObject.nodeName){
throw new error("Se requiere un objeto DOM de tipo SVG. Obtener con document.getElementById o un selector de jQuery $(contenedor).find('svg')[0]");
}
var svgData = new XMLSerializer().serializeToString(DOMObject);
var canvas = document.createElement("canvas");
canvas.width = $(DOMObject).width();
canvas.height = $(DOMObject).height();
var ctx = canvas.getContext( "2d" );
var img = new Image();//document.createElement("img");
img.setAttribute( "src", "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(svgData))) );
img.onload = function() {
ctx.drawImage( img, 0, 0 );
if(format === "jpeg" || format === "jpg"){
callback(canvas.toDataURL("image/jpeg"));
}else{
callback(canvas.toDataURL("image/png"));
}
};
return true;
};
但它抛出的安全错误我试图设置交叉来源但仍然是同样的错误