Skip to content

Instantly share code, notes, and snippets.

@ochilab
Created May 3, 2020 10:05
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 ochilab/7dfa6f8dd56d46a3f12e3ed087a74e77 to your computer and use it in GitHub Desktop.
Save ochilab/7dfa6f8dd56d46a3f12e3ed087a74e77 to your computer and use it in GitHub Desktop.
JavaScriptでデータをファイルとしてダウンロードさせる
function downloadFile() {
var content="aaaa,bbbbb,ccccc";
var blob = new Blob([ content ], { "type" : "text/csv"});
var downLoadLink = document.createElement("a");
downLoadLink.download ="test.csv";
downLoadLink.href = window.URL.createObjectURL(blob);
downLoadLink.dataset.downloadurl = ["text/plain", downLoadLink.download, downLoadLink.href].join(":");
downLoadLink.click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment