87,993
社区成员
发帖
与我相关
我的任务
分享
<div>
<style>
.content-download-dynamic {
background: #f4c000;
box-shadow: 0 8px 12px 0 rgba(244,194,41,.56);
}
.content-download {
width: 208px;
height: 64px;
font-size: 18px;
font-weight: 600;
border-radius: 10px;
border: 0;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
right:auto;
}
button {
margin: 0;
padding: 0;
outline: none;
border-radius: 0;
background-color: transparent;
line-height: inherit;
width: -webkit-max-content;
width: -moz-max-content;
width: max-content;
}
</style>
<script>
function forceDownload(link){
var url = link.getAttribute("data-href");
var fileName = link.getAttribute("download");
link.innerText = "下载中...";
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "blob";
xhr.onload = function(){
var urlCreator = window.URL || window.webkitURL;
var imageUrl = urlCreator.createObjectURL(this.response);
var tag = document.createElement('a');
tag.href = imageUrl;
tag.download = fileName;
document.body.appendChild(tag);
tag.click();
document.body.removeChild(tag);
link.innerText="https://wallpaperm.cmcm.com/48a06bc0f87cbcb9aeca96370408bc3c.jpg"; //下载图片地址
}
xhr.send();
}
</script>
<a href="#" data-href="https://wallpaperm.cmcm.com/48a06bc0f87cbcb9aeca96370408bc3c.jpg" download="Images.jpg" class="content-download content-download-dynamic" onclick='forceDownload(this)'>下载高清壁纸</a>
</div>