2019-06-12 07:14

如何在没有按钮的情况下自动保存html textarea? [关闭]


I have a textarea in my html like this:

<textarea id="area1"></textarea>

When visitors copy/paste or type something in this area i want it to save to a txt file without the visitor having to click any button.

Looked all over the web but can't find any solution.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongmeiran609914 dongmeiran609914 2年前

    write JS function, that saves info in .txt file. Let's say, function name is saveToTxt(). Then trigger that function onChange:

    <textarea id="area1" onChange="saveToTxt(this);"></textarea>


    Assume that, saveToTxt() is something like that:

    function saveToTxt(fld) {
        const textAreaValue = fld.value;
        // then use textArea variable as container of textarea-content
        // and then treat it as you want.
    点赞 评论 复制链接分享
  • dtzhfb4869 dtzhfb4869 2年前

    This example show how to save content automatically 2s after changing. It can prevent from doing save for every character typed.

    var t;
    function save() {
      t = setTimeout(function() {
        console.log('All changes saved'); // save here
      }, 2000);
    <textarea onchange="save();" onkeyup="save();"></textarea>

    点赞 评论 复制链接分享