Workaround! : Getimagedata on ' canvasrenderingcontext2d ': The canvas had been tainted by cross-origin data.

Source: Internet
Author: User
Tags tainted

Uncaught securityerror:failed to execute ' getimagedata ' on ' canvasrenderingcontext2d ': The canvas had been tainted by CRO Ss-origin data.

Recently in self-study HTML5 CSS3 very recommended Li Gang of this book

Failed to execute ' getimagedata ' on ' canvasrenderingcontext2d ' because there was a problem with chrome cross-domain access JSON, so I know it's a browser configuration problem Allow-file-access-from-files on it, found that there is no answer on the internet, so I think why my company can, I every time the company with Chrome will appear a hint that the browser security can be low, I know, because the company to minimize the security performance, So there's no JSON cross-domain and getimagedata issues, so I open the browser, and that's the problem.

Solution 1:--disable-web-security, we add this sentence to the target. Remember that there is a space in the middle, then close the browser, re-open the input address manually (I am the local file HTML directly drag and drop into the Do not use DW shortcut F12 Open, the first invalid, I do not know why) problem resolution (refer to the picture attached 1), accompanied by the cause of the problem:

1. First, there is no server environment (such as: local HTML page, operation of local images),it will be reported "unable to get image data from canvas because the canvas had been tainted by Cross-origin data" error. because the local test picture is within the folder, JS cross-domain limit is not able to get the data under the same domain name,and the local location is no domain name, so the browser think you are cross-domain, resulting in an error. 2. to prevent spoofing, the browser tracks image data. when a picture of a canvas is placed on a canvas, the canvas becomes "tainted" (contaminated), The browser will not let you manipulate any of the canvas's pixels. is to prevent multiple types of XSS/CSRF attacks (two typical cross-site attacks).

Workaround 2:

Convert the picture into a string to save in the browser, use and then convert back to be interested in reference

http://blog.csdn.net/molaifeng/article/details/42293509

Photo: attached 1


Workaround! : Getimagedata on ' canvasrenderingcontext2d ': The canvas had been tainted by cross-origin data.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.