Skip to content

Instantly share code, notes, and snippets.

@mgng mgng/gero.html
Created Aug 22, 2012

Embed
What would you like to do?
javascriptでテキストエリアの文字列をダウンロードさせる
<p>
<textarea id="id_textarea">あいうえおインータネット</textarea><br />
<button onclick="kuso()">ダウンロード</button>
<div id="id_download"></div>
</p>
<script type="text/javascript">
function kuso(){ if(window.File){
var b = new Blob(
[ document.getElementById('id_textarea').value ],
{ "type" : "text/plain" }
);
var c = window.URL
? function(b){ return window.URL.createObjectURL(b); }
: window.webkitURL
? function(b){ return window.webkitURL.createObjectURL(b); }
: undefined;
if ( c ) {
document.getElementById("id_download").innerHTML = '<a href="' + c(b) + '" target="_blank">ダウンロード</a>';
}
}}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.