Home > front end >  Click the button to download images/turn great god help see little mistakes
Click the button to download images/turn great god help see little mistakes

Time:12-04

 

<style>
. The content - download - dynamic {
Background: # f4c000;
Box - shadow: 0 px 8 12 px 0 rgba (9, 244194. 56);
}
. The content - download {
Width: 208 px;
Height: 64 px;
The font - size: 18 px;
The font - weight: 600;
border-radius: 10px;
Border: 0;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
Right: auto;
}
The button {
margin: 0;
padding: 0;
outline: none;
Border - the radius: 0;
Background - color: transparent;
The line - height: inherit;
Width: - its - Max - content;
Width: - moz - Max - content;
Width: Max - content;
}
</style>
<script>
The function forceDownload (link) {
Var url=link. The getAttribute (data - "href");
Var fileName=link. The getAttribute (" download ");
Download link. The innerText="... ";
Var XHR=new XMLHttpRequest ();
XHR. Open (" GET ", url, true);
XHR. ResponseType="blob";
XHR. onl oad=function () {
Var urlCreator=window. URL | | window. WebkitURL;
Var imageUrl=urlCreator. CreateObjectURL (enclosing response).
Var tag=document. The createElement method (' a ');
The tag. Href=HTTP://https://bbs.csdn.net/topics/imageUrl;
The tag. The download=fileName;
Document. The body. The appendChild (tag);
The tag. The click ();
Document. Body. RemoveChild (tag);
The link. The innerText="https://img.codepudding.com/202012/174360040606181.jpg";//download images address
}
XHR. The send ();
}
</script>




Error: click on the button, the download of the images are failure, don't know what went wrong, please give a glance, a great god help correct
  • Related