Created
September 9, 2017 04:50
-
-
Save daijinload/094a4df1d8853276b10539d882666a2c to your computer and use it in GitHub Desktop.
postして、帰ってきたものをダウンロードしちゃうというね。文字列でもおk。レンダリングしないから動作的には軽いのさ。
This file contains hidden or 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 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