The javascript-canvas image is from api.xx.com. the current domain is m.xx.com. when you call canvas. toDataURL (), the cross-origin is reported.

Source: Internet
Author: User
Tags subdomain
A project uses the Canvas label of Html5. The image displayed by canvas comes from the subdomain of api.xx.com. the domain of the current page is m.xx.com. once it is called through JS: canvas. toDataURL () will report the cross-origin issue: Redirectatorigin & #039; api. xx. c... A project uses the Canvas label of Html5. The image displayed by canvas comes from the subdomain of api.xx.com. the domain of the current page is m.xx.com. once it is called through JS: canvas. toDataURL () will report Cross-origin issues:

Redirect at origin 'http: // api.xx.com 'has been blocked from loading by Cross-Origin Resource Sharing policy: no 'Access-Control-Allow-Origin' header is present on the requested resource. origin 'http: // m.xx.com 'is therefore not allowed access.

Is there any related solution for upyun, or can I add Access-Control-Allow-Origin open Control for the header of the cross-Origin request for images?

How can I add Access-Control-Allow-Origin to the request Image header?

Reply content:

A project uses the Canvas label of Html5. The image displayed by canvas comes from the subdomain of api.xx.com. the domain of the current page is m.xx.com. once it is called through JS: canvas. toDataURL () will report Cross-origin issues:

Redirect at origin 'http: // api.xx.com 'has been blocked from loading by Cross-Origin Resource Sharing policy: no 'Access-Control-Allow-Origin' header is present on the requested resource. origin 'http: // m.xx.com 'is therefore not allowed access.

Is there any related solution for upyun, or can I add Access-Control-Allow-Origin open Control for the header of the cross-Origin request for images?

How can I add Access-Control-Allow-Origin to the request Image header?

I have encountered this problem before, because the images used are not on the same server.
At that time, the solution was to get the image file content through the server and then output the content on the html page. in this way, the cross-domain problem of images can be solved. (But it may not be correct !)

Addimg.crossOrigin = "Anonymous"
Access-Control-Allow-OriginThis is sent from the background.
I have encountered this problem before, but I didn't handle it like this. for some other reasons, I have to give up obtaining images from the server and change it to a local one.

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.