因此,作为处理我网站上某些报告下载的一部分,图像会从站点导出到同一域中的脚本以生成下载,但它似乎只会引发SecurityError。
这与其他问题不太相似,严格来说,因为图像的来源是同一个域。我没有把它从其他网站上拉下来。
我猜测这与IE9有关,将数据URL视为污点并拒绝我的努力。这是我唯一猜到的。
代码:
//i is part of a loop, this is referring to a Vue instance, but that shouldn't matter
var svg = this.charts[i].getSVG(); //Highcharts method.
var svgSize = {height: this.charts[i].chartHeight ,width: this.charts[i].chartWidth};//svg.getBoundingClientRect();
var canvas = document.createElement('canvas');
canvas.height = svgSize.height;
canvas.width = svgSize.width;
var ctx = canvas.getContext('2d');
//Image it up
var img = document.createElement('img');
img.setAttribute('src', 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg))));
img.setAttribute('crossOrigin', 'anonymous');
img.onload = function() {
ctx.drawImage(img, 0, 0);
//Add the image
var url = canvas.toDataURL('image/png'); //ERROR HERE
//url is stored into an array, irrelevant.
//If it exists in the next element, continue;
if(typeof self.charts[i+1] != "undefined") { self.generateChartByIdx(i+1); }
};
引发SCRIPT5022: SecurityError