跨源资源共享策略错误拒绝跨源映像加载

时间:2016-01-20 01:37:17

标签: javascript cross-domain

我发现了一个非常奇怪的问题。如下面的代码,我使用canvas来上传本地图片。但有时候,在将图像绘制到画布之前,Chrome会抛出“跨源资源共享策略拒绝交叉原始图像加载”的错误!这不是图片的问题,因为我们可以使用另一台计算机上传。

我正在使用Chrome 31,Windows 7 x64

if (!options) return;
this.options = options || {};

// 图片src为必须
if (!this.options.src) return;

this._image = new Image();
this._image.crossOrigin = "*"; // 解决跨域问题,以免污染画布
this._image.src = this.options.src;

if (this.options.isMoving === undefined) this.options.isMoving = true;
if (this.options.isMouseWheel === undefined) this.options.isMouseWheel = true;
if (this.options.isResize === undefined) this.options.isResize = false;
if (this.options.fillStyle === undefined) this.options.fillStyle = 'white';

You could see the error through the link

1 个答案:

答案 0 :(得分:0)

当错误试图告诉您时,除非您被允许读取图像URL(无论是来自您自己的主机还是通过CORS),否则无法将图像绘制到画布上。 / p>