Created
October 25, 2017 10:01
-
-
Save shenqihui/1a9cc5f28e49a4f30c3f50686bb3e60d to your computer and use it in GitHub Desktop.
react download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const onDownload = (link) => { | |
const tempLink = document.createElement('a'); | |
tempLink.href = link; | |
tempLink.setAttribute('download', 'img.png'); | |
tempLink.setAttribute('target', '_blank'); | |
document.body.appendChild(tempLink); | |
setTimeout(() => { | |
tempLink.setAttribute('download', 'qrcode.png'); | |
tempLink.click(); | |
document.body.removeChild(tempLink); | |
}, 1000); | |
}; | |
<a onClick={onDownload.bind(this, 'https://www.baidu.com/img/bd_logo1.png')}>Download</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment