search

Home  >  Q&A  >  body text

javascript - canvas toDataURL() cross-domain issue

The picture is placed on Youpaiyun. When canvas calls the picture, todataURl will report an error in the end. Is there any solution?
Baidu also looked at many solutions but none of them could be implemented. .
Error message:

Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
淡淡烟草味淡淡烟草味2741 days ago500

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-16 13:38:18

    If it is new Image(), add the following settings:

    // 引用外部图片,需设置 crossOrigin 属性,否则 toDataURL 调用异常
    image.setAttribute('crossOrigin', 'anonymous');
    

    Reference question: /q/10...

    reply
    0
  • Cancelreply