0

I have the same exact problem as the user in this question. I am using this code:

function imgData(img) {
    var src_canvas = document.createElement('canvas');
    src_canvas.width = this.width;
    src_canvas.height = this.height;

    var src_ctx = src_canvas.getContext('2d');
    src_ctx.drawImage(img, 0, 0);
    var src_data = src_ctx.getImageData(0, 0, this.width, this.height).data;
}

And it always generates this error on Chrome:

Uncaught SecurityError: An attempt was made to break through the security policy of the user agent. Resources.js:27
Unable to get image data from canvas because the canvas has been tainted by cross-origin data. Resources.js:27

I am extremely new to JavaScript and have no idea what the issue is here. The internet seems to be at a loss today as well so I am now here. The answers to the question I referenced refer to the issue being he was trying to use images from outside sources (outside of his file system). The problem is, I'm not. I am just running the files in Chrome on my file system. The image is also in my file system and not anywhere I would think would merit a security error. Any thoughts? Am I being a moron?

4

1 回答 1

5

您是否直接从文件系统访问 HTML / JavaScript 作为文件,而不是在网络服务器后面?如果是这样,请尝试后者,如果您要求大多数浏览器在网络服务器之外获取数据(即使它们在您自己的文件系统中),它们都会出现跨域安全问题。

于 2013-10-26T01:56:50.863 回答