Upload Picture screenshot Preview control does not show cropper.js cross-domain issues

Source: Internet
Author: User

Upload pictures to the image server, because the domain name is different, there will be cross-domain issues.

No ' Access-control-allow-origin ' header is present on the requested resource. Origin ' http://img.xxx.com ' is therefore not allowed access.

Look after the code found, cropper.js inside the image reference path to make a judgment, to the IMG tag added crossorigin= "Anonymous" (anonymous cross-domain attribute).

It also uses the XMLHttpRequest GET request to access the IMG reference path, which does not have access. You need to add access-control-allow-origin:* to the image server, or to the request header that is returned, or Access-control-allow-origin: request source domain.

A quick and easy solution is to remove the cross-domain attribute directly from the Cropper.js, because the default slices can also be displayed across domains.

For the lower version of Cropper.js, you can do this:

     This. $clone = $clone = $ ('  '); $clone. One (' Load ', $.proxy (function () {      varNaturalwidth = $clone. Prop (' Naturalwidth ') | |$clone. Width (), Naturalheight= $clone. Prop (' Naturalheight ') | |$clone. Height ();  This. Image ={naturalwidth:naturalwidth, naturalheight:naturalheight, Aspectratio:naturalwidth/naturalheight, rotate:0      };  This. url =URL;  This. Ready =true;  This. Build (); },  This). One (' Error ',function() {$clone. Remove (); }). attr ({//Crossorigin:crossorigin,//"Crossorigin" must before "src" (#271)Src:bustcacheurl | |URL});

It would be nice to comment out that line of Crossorigin.

For the high version (I used the Cropper v2.3.4) because the code is adjusted, find function Getcrossorigin (crossorigin), the line that returns the cross-domain code is commented out, the return of an empty string is good.

That's how I changed it:

  function Getcrossorigin (crossorigin) {      //return crossorigin? ' crossorigin= ' + crossorigin + ' "': ';      return ';  }

It can be displayed.

Upload Picture preview control does not show cropper.js cross-domain issues

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.