簡體   English   中英

使用javascript將數據保存到文本文件

[英]Saving data to a text file using javascript

我找到了一個腳本,用於將文本框的內容寫入文本文件,並顯示下載鏈接。

但是,現在我需要修改此代碼的幫助,以在單擊按鈕后將文本文件保存在服務器中的特定位置。

這是代碼:

<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>

請指教。

您將需要學習服務器端實踐的后端開發。 如果沒有后端,客戶端將無法對服務器進行任何修改。 (那將是一個巨大的安全漏洞!)我建議在這里學習NodeJS: https//www.w3schools.com/nodejs/

一旦您變得更加熟悉並認為您准備好再次參加該項目,請給我直接發送消息,我會為您指明正確的方向。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM