Created
January 15, 2020 09:52
-
-
Save shammelburg/af5b8e5c453a19e84dd9cd42ec7003d7 to your computer and use it in GitHub Desktop.
JavaScript File Download
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 createDownloadLink(str, fileName, contentType) { | |
var blob = new Blob([str], { | |
type: "application/json;charset=utf-8" | |
}); | |
var blobUrl = URL.createObjectURL(blob); | |
var a = document.createElement("a"); | |
a.href = blobUrl; | |
a.setAttribute("download", fileName + ".json"); | |
document.body.appendChild(a); | |
a.click(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment