Created
March 18, 2015 11:13
-
-
Save sasekazu/643045e238e00ad5367f to your computer and use it in GitHub Desktop.
File API でテキストファイル書き出し
This file contains 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 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