Is it possible to write data to file using only JavaScript?

后端 未结 10 1329
梦如初夏
梦如初夏 2020-11-21 15:45

I want to Write Data to existing file using JavaScript. I don\'t want to print it on console. I want to Actually Write data to abc.txt. I read many answered que

10条回答
  •  遥遥无期
    2020-11-21 15:55

    Use the code by the user @useless-code above (https://stackoverflow.com/a/21016088/327386) to generate the file. If you want to download the file automatically, pass the textFile that was just generated to this function:

    var downloadFile = function downloadURL(url) {
        var hiddenIFrameID = 'hiddenDownloader',
        iframe = document.getElementById(hiddenIFrameID);
        if (iframe === null) {
            iframe = document.createElement('iframe');
            iframe.id = hiddenIFrameID;
            iframe.style.display = 'none';
            document.body.appendChild(iframe);
        }
        iframe.src = url;
    }
    

提交回复
热议问题