Created
June 28, 2022 09:49
-
-
Save NaClYen/20669b8e9035b37b3434e61e89f7ffea to your computer and use it in GitHub Desktop.
auto download file in web
This file contains hidden or 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
function download(source) { | |
const fileName = source.split("/").pop(); | |
let el = document.createElement("a"); | |
el.setAttribute("href", source); | |
el.setAttribute("download", fileName); | |
document.body.appendChild(el); | |
el.click(); | |
el.remove(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref: https://www.codegrepper.com/code-examples/javascript/javascript+download+image+from+url