आधिकारिक विनिर्देश
आधिकारिक विनिर्देश crossorigin एट्रिब्यूट को इस प्रकार बताता है:
The crossorigin attribute is a CORS settings attribute. Its purpose is to allow images from third-party sites that allow cross-origin access to be used with canvas.
यह कैसे काम करता है
जब इसे CORS हेडर के साथ जोड़ा जाता है, तो यह <img> एलिमेंट द्वारा परिभाषित इमेजेस को, विदेशी मूल से लोड होने पर, canvas में उपयोग करने की अनुमति देगा। प्रक्रिया वर्तमान मूल से लोड होने जैसी होगी।
उपयोग का मामला: JavaScript एरर्स लॉग करना
if (securityOrigin()->canRequest(targetUrl)) {
msg = myError;
line = myLineNumber;
source = sourceURL;
} else {
msg = "Error!";
source = String();
line = 0;
}
यह क्रॉस-ओरिजिन इमेजेस के साथ canvas टैंटिंग मुद्दों को हल करने में मदद करता है।