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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/yujianping_123/article/details/99302452

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>

猜你喜欢

转载自blog.csdn.net/yujianping_123/article/details/99302452