点击按钮下载图片

function downloadImg(url, name) {
    var x=new XMLHttpRequest();
    var resourceUrl = url;
    x.open("GET", resourceUrl, true);
    x.responseType = 'blob';
    x.onload=function(e){
        var url = window.URL.createObjectURL(x.response)
        var a = document.createElement('a');
        a.href = url;
        a.download = name;
        a.click();
    }
    x.send();
}

 

 

最后修改于 2020-03-08 13:39:00
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付
上一篇