1 downloadImg(url:string,name:string):void{ 2 let xhr = new XMLHttpRequest(); 3 xhr.responseType = 'blob'; 4 xhr.open('GET', url); 5 xhr.send(); 6 xhr.addEventListener('load', function() { 7 let blob = xhr.response; 8 let downloadLink = document.createElement('a'); 9 downloadLink.href = URL.createObjectURL(blob); 10 downloadLink.download = name; 11 downloadLink.click(); 12 });
标签:浏览器,string,当前页,downloadLink,js,xhr,let,blob From: https://www.cnblogs.com/yanwuming/p/17320911.html