【发布时间】:2013-08-09 08:10:48
【问题描述】:
我正在开发一个项目,该项目使用画布自动裁剪图像,然后返回其数据 URL。它使用来自外部服务器的图像,该服务器具有适当的 CORS 标头,以允许图像在被裁剪后转换为数据 URI,即使它们是跨域的。
该代码在除 IE 10 之外的所有浏览器中都能完美运行(并且没有安全错误!),其中在调用 canvas.toDataURL() 时会抛出“SCRIPT5022: SecurityError”。
这是 IE 中的错误还是我需要在我的代码中做一些不同的事情才能使它在 Idiot Exploder 中工作?谢谢。 -斯科特
编辑 这是我用来创建和绘制画布的(大部分)代码;
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
var img = new Image();
img.src = imageServerURL + '?id=' + imageIdToGet; // imageServerURL points to a different domain but the server has headers allowing requests from my domain
/*
code here that defines the cropping area, in variables like ulX, lrY, etc.
*/
ctx.beginPath();
ctx.moveTo(ulX, ulY);
ctx.lineTo(urX, urY);
ctx.lineTo(lrX, lrY);
ctx.lineTo(llX, llY);
ctx.closePath();
ctx.clip();
ctx.drawImage(img, 0, 0);
var url = canvas.toDataURL(); // This succeeds in all other browsers but throws a SecurityError in IE
【问题讨论】:
-
首先,请向我们展示您的代码和/或说明此画布的创建方式及其包含的内容。
-
原始问题已编辑。
标签: canvas internet-explorer-10 cors same-origin-policy