html2canvas跨域解决方案

html2canvas(document.getElementById('imgbg'), {
      useCORS: true, //(图片跨域相关)
      allowTaint: false, //允许跨域(图片跨域相关)
      canvas: canvas,
      taintTest: true, //是否在渲染前测试图片
      onrendered: function(canvas) {
      document.getElementById('imgResult').src = canvas.toDataURL();
    }
});

核心代码

useCORS:true,//(图片跨域相关)
allowTaint:false,//允许跨域(图片跨域相关)

Ps:html2canvas截取超长dom是会有问题的

推荐另外一个插件https://github.com/tsayen/dom-to-image

你可能感兴趣的:(html2canvas跨域解决方案)