Skip to content

Instantly share code, notes, and snippets.

@shammelburg
Created January 15, 2020 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shammelburg/af5b8e5c453a19e84dd9cd42ec7003d7 to your computer and use it in GitHub Desktop.
Save shammelburg/af5b8e5c453a19e84dd9cd42ec7003d7 to your computer and use it in GitHub Desktop.
JavaScript File Download
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