Commit f43d32ab authored by 柳 佳乐's avatar 柳 佳乐
Browse files

20221117

parent 7c43290b
<body>
<button onclick="download()">下载(跨域)</button>
<script>
function download() {
var url = 'http://39.174.37.19:11538/finance2/36f95c32cb9421b5df30aa99a99c788.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=1N6XFL78EG190UUFHM53%2F20221115%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20221115T065613Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=0e3420279405fd4e88fbf33c997d12f13766dc7ffd9e4378fc5e43a229aa6236';
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true); // 异步
xhr.responseType = 'blob'; // blob 类型
xhr.onload = function () {
if (xhr.status != 200) {
alert('下载异常!');
return;
}
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(xhr.response, filename);
} else {
var newUrl = window.URL.createObjectURL(xhr.response);
var a = document.createElement('a');
a.setAttribute('href', newUrl);
a.setAttribute('target', '_blank');
a.setAttribute('download', 'hh.jpg'); // 自定义文件名(有效)
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
};
xhr.send();
}
</script>
</body>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment