问题
I have problem with this code:
var imgPixels = canvasContext.getImageData(0, 0, imgW, imgH);
Error from Google Chrome console is:
Unable to get image data from canvas because the canvas has been tainted by cross-origin data.
It's because i have run this site on the domain1.com, img src is on the domain2.com and later i want to set new src with a local (modified) data (as below), i think.
return canvas.toDataURL();
I have tried many ways to allow cross-origin access, but nothing works:
if (canvas.crossOriginKeyword)
{
canvas.removeAttribute("crossorigin");
}
if (canvasContext.crossOriginKeyword)
{
canvasContext.removeAttribute("crossorigin");
}
My .htaccess file contains:
Header always set Access-Control-Allow-Origin *
And I also tried:
<?php
header('Access-Control-Allow-Origin: *');
?>
My Script should work on many browsers, and many servers, so i want to avoid modifying browser or apache configuration, unless it's really needed.
I can't use a proxy.
Please, help me :)
来源:https://stackoverflow.com/questions/11794025/how-to-allow-cross-origin-access-to-imgs-and-canvases