[content]content
を[fileName]fileName
でダンロードしたい場合の実装
[content]content
は生の文字列
var downloadAsFile = function(fileName, content) {
var blob = new Blob([content]);
var url = window.URL || window.webkitURL;
var blobURL = url.createObjectURL(blob);
var a = document.createElement('a');
a.download = fileName;
a.href = blobURL;
a.click();
};
コレでも可
var downloadAsFile = function(fileName, content) {
var a = document.createElement('a');
a.download = fileName;
a.href = 'data:application/octet-stream,'+encodeURIComponent(content);
a.click();
};