图像OnLoad服务器

时间:2014-10-09 16:46:43

标签: javascript image onload-event

请有人帮忙,我正在将svg xml转换为image然后on image onload事件将其转换为实际的dataURI。这在我的本地主机上完美运行,但是当部署到服务器时,我注意到onload事件永远不会再被触发。这在本地所有浏览器中都可以正常工作,但是当部署到服务器时在Chrome和Safari中不起作用这是片段

var imgString = 'data:image/svg+xml;base64,' + window.btoa(unescape(encodeURIComponent(sourceSVG)));
var image = new Image();
image.onload = function () {
var canvas = document.createElement('canvas');
canvas.width = 400;
canvas.height = 400;
var context = canvas.getContext('2d');
context.drawImage(image, 0, 0);
img = canvas.toDataURL('image/png');
var imageSelected = $('.highImage');
if (section == "high") {
imageSelected = $('.lowImage');
}
imageSelected.find('img').attr({ 'src': img, 'height': '100%', 'width': '100%' });
var context = canvas.getContext('2d');
canvas.width = 0;
canvas.height = 0;
context.clearRect(0, 0, canvas.width, canvas.height);
$('#' + targetCanvas).css({ 'height': 0, 'width': 0 });
};

image.src = "";
image.src = imgString;

有人可以帮助我,它让我疯狂

0 个答案:

没有答案