【问题标题】:Why is Image request been blocked by CORS on MDN if crossOrigin is anonymous? [duplicate]如果 crossOrigin 是匿名的,为什么 MDN 上的 CORS 会阻止图像请求? [复制]
【发布时间】:2020-07-13 10:55:22
【问题描述】:

我尝试创建一个图像来从 Tenor 加载一些 gif,但有些被 CORS 阻止,而不是所有 gif。谁能解释一下?

在https://developer.mozilla.org/上执行下面的脚本

function loadImage(crossOrigin) {
  const img = new Image()
  if(crossOrigin) img.crossOrigin = 'anonymous';
  img.src="https://media.tenor.com/images/d5b11025a5f24a73c53adeae124aff72/tenor.gif"
}
loadImage(false)
loadImage(true)

【问题讨论】:

    标签: image cors


    【解决方案1】:

    在 non-crossorigin 中加载图像,然后在 crossorigin 中导致 cors,因为它是用 non-crossorigin 缓存的。

    我找到了这个答案https://stackoverflow.com/a/25898528/2449929

    【讨论】:

      猜你喜欢
      • 2020-09-05
      • 2021-12-17
      • 2015-08-20
      • 1970-01-01
      • 1970-01-01
      • 2014-07-29
      • 2018-03-18
      • 2017-05-03
      • 1970-01-01
      相关资源
      最近更新 更多