zoukankan      html  css  js  c++  java
  • html2canvas 跨域图片无法正常加载问题解决办法

    //解决跨域图片无法加载问题,将远程图片转换为base64,图片直接赋值src即可,imgUrl为远程图片地址
    function getBase64(imgUrl) {
    window.URL = window.URL || window.webkitURL;
    var xhr = new XMLHttpRequest();
    xhr.open("get", imgUrl, true);
    // 至关重要
    xhr.responseType = "blob";
    xhr.onload = function () {
    if (this.status == 200) {
    //得到一个blob对象
    var blob = this.response;
    console.log("blob", blob)
    // 至关重要
    let oFileReader = new FileReader();
    oFileReader.onloadend = function (e) {
    // 此处拿到的已经是 base64的图片了
    let base64 = e.target.result;
    $(".ewm").attr("src", base64);
    };
    oFileReader.readAsDataURL(blob);

    }
    }
    xhr.send();
    }

  • 相关阅读:
    整合规则引擎urule
    vue学习
    发送put请求,get请求
    jpa自定义字段
    spring的3种配置方式
    netty
    springsercurity和shiro
    git报错
    Scrapy全站数据爬取
    python操作Excel模块openpyxl
  • 原文地址:https://www.cnblogs.com/wuchaofan1993/p/14200976.html
Copyright © 2011-2022 走看看