CORS不适用于设置了标头的图片

时间:2018-10-18 21:15:01

标签: .htaccess header cors

我得到以下信息:CORS策略已阻止从来源“ http://example.com/image.png”访问“ http://fiddle.jshell.net”处的图像:上没有“ Access-Control-Allow-Origin”标头请求的资源。因此,不允许访问来源“ http://fiddle.jshell.net”。

<canvas id="myCanvas"></canvas>
..
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = document.getElementById("scream");

var i = new Image();
      i.crossOrigin = "Anonymous";

i.onload = function() {
    c.width = this.width;
  c.height = this.height;

  ctx.drawImage(this, 0, 0); 

  console.log(c.toDataURL());
}

i.src = 'http://example.com/image.png';

我的服务器设置上具有.htaccess,如下所示:

<ifmodule mod_headers.c="">
   Header set Access-Control-Allow-Origin "*" 
   Header set Access-Control-Allow-Methods: "*"
   Header set Access-Control-Allow-Headers: "Origin, X-Requested-With, Content-Type, Accept, Authorization"
</ifmodule>

还有其他我想念的东西吗?

0 个答案:

没有答案