ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
先将url转成blob类文件对象,在通过a标签的download属性下载,并重命名 仅支持Chrome Firefox ``` var url = 'https://b-gold-cdn.xitu.io/v3/static/img/logo.a7995ad.svg' var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'blob'; xhr.onload = function() { if (xhr.status === 200) { var blob = xhr.response var link = document.createElement('a'); var body = document.querySelector('body'); link.href = window.URL.createObjectURL(blob); link.download = '测试'; link.style.display = 'none'; body.appendChild(link); link.click(); body.removeChild(link); } }; xhr.send(); ```