Skip to content

Instantly share code, notes, and snippets.

@daijinload
Created September 9, 2017 04:50
Embed
What would you like to do?
postして、帰ってきたものをダウンロードしちゃうというね。文字列でもおk。レンダリングしないから動作的には軽いのさ。
function downloadData(content, filename, mimetype) {
// debugger;
if (!mimetype) {
mimetype = 'application/octet-stream';
if (typeof content === 'string') {
mimetype = 'application/octet-stream;charset=UTF-8';
}
}
var url = (window.URL || window.webkitURL).createObjectURL(new Blob([content], { 'type': mimetype }));
var a = document.createElement('a');
var evt = document.createEvent('MouseEvents');
a.target = '_blank';
a.download = filename || 'aaa.txt';
a.href = url;
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(evt);
}
downloadData('みくだよーさん')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment