Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

canvas.toDataURL("image/jpg;base64;"); canvas提交img时报错:

Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

原因是:

your local drive is declared to be "other-domain" and will taint the canvas, your most sensitive info is likely on your local drive!

简单来讲,就是跨域问题。

解决方法:

img.setAttribute("crossOrigin",'anonymous');

或者

img.crossOrigin = 'anonymous';

可能还是不行,请看下面:

img html tag

<img crossorigin="anonymous">...</img>


版权声明:本文为yujianping_123原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。