程序背景
想在本地测试html
发生的错误
index.js:33 Uncaught DOMException: Failed to execute ‘toDataURL’ on ‘HTMLCanvasElement’: Tainted canvases may not be exported.
在程序中运用了toDataURL导致的如上的错误。
解决方式:添加代码image.setAttribute('crossOrigin','anonymous');
在var image
之后就行
新出现的错误
在Chrome中运行html文件,发现问题(如下图)。
Access to Image at ‘file:///D:/Puzzle-master/img/shulan.jpg’ from origin ‘null’ has been blocked by CORS policy: Invalid response. Origin ‘null’ is therefore not allowed access.
解决方式:在Chrome的快捷方式中,右键点击属性,在其中找到快捷方式的标签,点击后在中间位置有个目标,将目标最后添加 --allow-file-access-from-files
。
PS:其中- -之前应该是有个空格的,希望可以解决大家出现的问题。