Web programming: cross-origin blockage with getImageData or putImageData

Self-tutoring about how to deal with cross-origin denial: the tutor mentions a workaround.

I was experimenting with html canvas, specifically getImageData and putImageData, when I got a cross-origin complaint. The computer wouldn’t execute either getImageData or putImageData because, from its point of view, the file telling it to and the image file weren’t from the same origin. Such was my understanding, anyway.

Yet, what to do? I needed to perform a few tests, so needed those commands to work.

BTW: both files were from the same origin, even the same folder, on the computer I was using. However, I came to understand that JavaScript, for security reasons, is quite limited in working with local files.

In the end I uploaded both the script and the image file to the same folder on a server. JavaScript perceived those as from the same origin so then getImageData and putImageData worked.

Source:

developer.mozilla.org

developer.mozilla.org

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply