美文网首页
html2canvas跨域解决方案

html2canvas跨域解决方案

作者: 谭冉冉 | 来源:发表于2017-11-21 17:08 被阅读1878次
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跨域解决方案

      本文链接:https://www.haomeiwen.com/subject/hwmwvxtx.html