简体   繁体   English

控制台日志:Uncaught SecurityError:无法在'CanvasRenderingContext2D'上执行'getImageData':画布已被跨源数据污染

[英]Console Log: Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data

Hey I'm trying to implement a jquery plug in called backgroundcheck and it gives me the console log error of: "Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data." 嘿我正在尝试实现一个名为backgroundcheck的jquery插件,它给我控制台日志错误:“未捕获的SecurityError:在'CanvasRenderingContext2D'上执行'getImageData'失败:画布已被跨源数据污染。” I have done everything he says to do in the instructions but it doesn't work. 我已经完成了他在说明书中所做的一切,但它不起作用。 Any help would be greatly appreciated. 任何帮助将不胜感激。

UPDATE: 更新:

These are the three errors under the main error in the drop down menu. 这些是下拉菜单中主要错误下的三个错误。

calculatePixelBrightness VM682 background-check.min.js:571
processTargets VM682 background-check.min.js:631
check VM682 background-check.min.js:766

Here's a screenshot of it as well. 这是它的截图

jsFiddle Demo

The error is a result of the image being located at a different domain. 该错误是图像位于不同域的结果。 There is a surprisingly simple remedy to this though, which is to add the attribute crossDomain = "anonymous" to the image element itself. 然而,这有一个令人惊讶的简单补救措施,即将属性crossDomain = "anonymous"到图像元素本身。

For example, 例如,

<img src="http://i.imgur.com/UnnoYbv.jpg" crossOrigin="anonymous" draggable="false" />

This question seems as duplication of: 这个问题似乎重复:

Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data Uncaught SecurityError:无法在'CanvasRenderingContext2D'上执行'getImageData':画布已被跨源数据污染

The solution is probably the same. 解决方案可能是相同的。 When you load your html file from disk using: file://path/to/your/file.html , then Google Chrome and Opera will raise error at line including: imgData = ctx.getImageData(x1,y1,w,h); 使用: file://path/to/your/file.html从磁盘加载html文件时,谷歌Chrome和Opera将引发错误,包括: imgData = ctx.getImageData(x1,y1,w,h);

Solution is simple: start web server (apache, nginx) put your html file somewhere at web server and load your html file from: http://localhost/somewhere/file.html 解决方案很简单:启动Web服务器(apache,nginx)将您的html文件放在Web服务器的某处并从以下位置加载您的html文件: http://localhost/somewhere/file.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Uncaught SecurityError:无法在&#39;CanvasRenderingContext2D&#39;上执行&#39;getImageData&#39;:画布已被跨源数据污染 - Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data 无法执行&#39;getImageData&#39; - 画布已被跨源数据污染 - Failed to execute 'getImageData' - The canvas has been tainted by cross-origin data 未捕获的SecurityError:无法在“ CanvasRenderingContext2D”上执行“ getImageData”: - Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': 当我尝试使用getImageData时,如何解决“画布已被跨域数据污染”。 - How to solve “ The canvas has been tainted by cross-origin data.” when I try to use getImageData 如何修复 getImageData() 错误画布已被跨域数据污染? - How to fix getImageData() error The canvas has been tainted by cross-origin data? 未捕获的 DOMException:无法在“CanvasRenderingContext2D”上执行“getImageData” - Uncaught DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D' 画布已被跨源数据污染 - The canvas has been tainted by cross-origin data 画布受到跨源数据工作的污染 - canvas has been tainted by cross-origin data work around 未捕获的类型错误:无法在“CanvasRenderingContext2D”上执行“getImageData”:提供的双精度值是非有限的 - Uncaught TypeError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The provided double value is non-finite 错误:未捕获(承诺中)DOMException:无法在“CanvasRenderingContext2D”上执行“getImageData”:源高度为 0 - Error: Uncaught (in promise) DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source height is 0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM