As the question, when local output of the image address of the page (Html2Canvas.js), there are cross-domain problems in different sources, and the toDataURL access permission problem will occur:
【Redirect at origin 'http://sub1.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://sub2.xx.com' is therefore not allowed access.】
Solution:
According to error analysis, "Access-Control-Allow-Origin" is added to the control header, that is, permission to access the source file is allowed. Then we deal with this page [note that you want to output the picture of the page]:
var img = new Image;img.onload = myLoader;img.crossOrigin = 'anonymous'; //Optional value: anonymous, * img.src = 'http://myurl.com/...';
Or in HTML
<img src="" id="imgclcd" crossorigin="anonymous">
The core is that the request header contains the Origin: "anonymous" or "*" field , and the Access-Control-Allow-Origin: * field will be attached to the response header to solve the problem.
The above article quickly solves the cross-domain problem of Canvas.toDataURL pictures is all the content I have shared with you. I hope you can give you a reference and I hope you can support Wulin.com more.