Javascript-canvas image from api.xx.com, the current domain is m.xx.com, call Canvas.todataurl (), on the cross-domain

Source: Internet
Author: User
A project using the Canvas canvas label HTML5, canvas display of the image from the api.xx.com this subdomain, the current page of the domain is m.xx.com, once through the JS to call: Canvas.todataurl (), will report cross-domain issues:

Redirect at Origin ' http://api.xx.com ' have been blocked from loading by cross-origin Resource sharing Policy:no ' access-c Ontrol-allow-origin ' header is present on the requested resource. Origin ' http://m.xx.com ' is therefore not allowed access.

May I ask if there is a solution to the cloud, or can I add a head access-control-allow-origin open control over the cross-domain request for pictures?

How do I add access-control-allow-origin to the head of the requested picture?

Reply content:

A project using the Canvas canvas label HTML5, canvas display of the image from the api.xx.com this subdomain, the current page of the domain is m.xx.com, once through the JS to call: Canvas.todataurl (), will report cross-domain issues:

Redirect at Origin ' http://api.xx.com ' have been blocked from loading by cross-origin Resource sharing Policy:no ' access-c Ontrol-allow-origin ' header is present on the requested resource. Origin ' http://m.xx.com ' is therefore not allowed access.

May I ask if there is a solution to the cloud, or can I add a head access-control-allow-origin open control over the cross-domain request for pictures?

How do I add access-control-allow-origin to the head of the requested picture?

Previously encountered this problem, but also the sub-domain name of different cross-domain, because the use of the picture is not on the same server.
The solution adopted at that time was to get the picture file content through the server, and then output the HTML page, which would solve the cross-domain problem of the picture. (but maybe irrelevant!) )

Plusimg.crossOrigin = "Anonymous"
Access-Control-Allow-OriginThis stuff was sent backstage.
I've had this problem before, but I didn't do it, because for some other reason, you can only discard the image from the server and change it to local

  • 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.