Skip to content

Instantly share code, notes, and snippets.

@sasekazu
Created March 18, 2015 11:13
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 sasekazu/643045e238e00ad5367f to your computer and use it in GitHub Desktop.
Save sasekazu/643045e238e00ad5367f to your computer and use it in GitHub Desktop.
File API でテキストファイル書き出し
function fileSave(text, filename){
var blob = new Blob([text],{"type" : "text/html"});
var newElement = document.createElement("a"); // 新しいDOMを作成
newElement.textContent= "download"; // テキストはdownload
newElement.setAttribute('href', window.URL.createObjectURL(blob));
newElement.setAttribute('download', filename);
document.body.appendChild(newElement); // body直下に作成
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment