kennethcachia / background-check

Automatically switch to a darker or a lighter version of an element depending on the brightness of images behind it.
http://kennethcachia.com/background-check/
MIT License
3.27k stars 282 forks source link

Images from different domain #8

Closed kristabs closed 10 years ago

kristabs commented 10 years ago

Is there a way to patch JS so it would be able to work with images which is served from different domain? The page im working on serves images from CDN with dedicated domain name and JS produces these errors.

Unable to get image data from canvas because the canvas has been tainted by cross-origin data. background-check.min.js:5 Uncaught SecurityError: An attempt was made to break through the security policy of the user agent.

Im able to add Access-Control-Allow-Origin to images served but dont know how to patch JS for it to post Origin header.

kennethcachia commented 10 years ago

Check these out: cross-origin.html and cross-origin.js.

<img> in cross-origin.html has the crossorigin attribute while cross-origin.js takes care of image loading.

Demo.

kristabs commented 10 years ago

Very nice, thank you.

kennethcachia commented 10 years ago

No problem!