Can I save input from form to .txt in HTML, using JAVASCRIPT/jQuery, and then use it?

后端 未结 8 1531
情深已故
情深已故 2020-12-01 09:50

Is it possible to save textinput (locally) from a form to a textfile, and then open that document to use it later on?

Just using HTML, javascript and jQuery. No data

相关标签:
8条回答
  • 2020-12-01 10:39

    Or this will work too the same way but without a save as choice:

    <!DOCTYPE html>
    <html>
    <head>
    
    
    <script type='text/javascript'>//<![CDATA[
    window.onload=function(){
    (function () {
    var textFile = null,
      makeTextFile = function (text) {
        var data = new Blob([text], {type: 'text/plain'});
    
        // If we are replacing a previously generated file we need to
        // manually revoke the object URL to avoid memory leaks.
        if (textFile !== null) {
          window.URL.revokeObjectURL(textFile);
        }
    
        textFile = window.URL.createObjectURL(data);
    
        return textFile;
      };
    
    
      var create = document.getElementById('create'),
        textbox = document.getElementById('textbox');
    
      create.addEventListener('click', function () {
        var link = document.getElementById('downloadlink');
        link.href = makeTextFile(textbox.value);
        link.style.display = 'block';
      }, false);
    })();
    
    }//]]> 
    
    </script>
    
    
    </head>
    
    <body>
      <textarea id="textbox">Type something here</textarea> <button id="create">Create file</button> <a download="info.txt" id="downloadlink" style="display: none">Download</a>
    
    
      <script>
      // tell the embed parent frame the height of the content
      if (window.parent && window.parent.parent){
        window.parent.parent.postMessage(["resultsFrame", {
          height: document.body.getBoundingClientRect().height,
          slug: "qm5AG"
        }], "*")
      }
    </script>
    
    </body>
    
    </html>
    
    0 讨论(0)
  • 2020-12-01 10:39

    Answer is YES

    <html>
    <head>
    </head>
    <body>
    <script language="javascript">
    function WriteToFile()
    {
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var s = fso.CreateTextFile("C:\\NewFile.txt", true);
    var text=document.getElementById("TextArea1").innerText;
    s.WriteLine(text);
    s.WriteLine('***********************');
    s.Close();
    }
    </script>
    
    <form name="abc">
    <textarea name="text">FIFA</textarea>
    <button onclick="WriteToFile()">Click to save</Button>  
    </form> 
    
    </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题