LoginSignup
14

More than 5 years have passed since last update.

テキストエリアの内容をダウンロードできるようにする

Posted at

メモ

html
<textarea id="txtarea"></textarea>
<a href="" id="DLlink" download="download.txt">ダウンロード</a>
JavaScript
document.querySelector('#DLlink').onclick = function() {
    var text = document.querySelector('#txtarea').value;
    this.href = 'data:text/plain;charset=utf-8,'
        + encodeURIComponent(text);
};

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14