3

Hey I'm trying to implement a jquery plug in called backgroundcheck and it gives me the console log error of: "Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data." I have done everything he says to do in the instructions but it doesn't work. Any help would be greatly appreciated.

UPDATE:

These are the three errors under the main error in the drop down menu.

calculatePixelBrightness VM682 background-check.min.js:571
processTargets VM682 background-check.min.js:631
check VM682 background-check.min.js:766

Here's a screenshot of it as well.

Markus Hallcyon
  • 351
  • 2
  • 5
  • 15

2 Answers2

4

jsFiddle Demo

The error is a result of the image being located at a different domain. There is a surprisingly simple remedy to this though, which is to add the attribute crossDomain = "anonymous" to the image element itself.

For example,

<img src="http://i.imgur.com/UnnoYbv.jpg" crossOrigin="anonymous" draggable="false" />
Travis J
  • 81,153
  • 41
  • 202
  • 273
  • 1
    This didn't work. I'm using only local images! That's the weird thing. Please look at the update. Thanks SO much for the help! – Markus Hallcyon Nov 05 '14 at 01:18
-1

This question seems as duplication of:

Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data

The solution is probably the same. When you load your html file from disk using: file://path/to/your/file.html, then Google Chrome and Opera will raise error at line including: imgData = ctx.getImageData(x1,y1,w,h);

Solution is simple: start web server (apache, nginx) put your html file somewhere at web server and load your html file from: http://localhost/somewhere/file.html

Community
  • 1
  • 1
JiriHnidek
  • 523
  • 2
  • 6
  • 14