0
function saveTextAsFile() {
                var textToSave = document.getElementById("inputTextToSave").value;
                var textToSaveAsBlob = new Blob([textToSave], { type: "text/plain" });
                var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
                var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value;

                var downloadLink = document.createElement("a");
                downloadLink.download = fileNameToSaveAs;
                downloadLink.innerHTML = "Download File";
                downloadLink.href = textToSaveAsURL;
                downloadLink.onclick = countClicks;
               // downloadLink.onclick = destroyClickedElement;
                downloadLink.style.display = "none";
                document.body.appendChild(downloadLink);

                downloadLink.click();
            }
            function countClicks() {
                if (localStorage.clickcount >= 5) {

                    localStorage.clickcount = 0; // reset count
                    localStorage.clickcount1++;    // increase next count
                }
                if (typeof (Storage) !== "undefined") {
                    if (localStorage.clickcount) {
                        localStorage.clickcount = Number(localStorage.clickcount) + 1;
                    } else {
                        localStorage.clickcount = 1;
                    }
                    document.getElementById("result").innerHTML = "Number of Notes Saved:" + localStorage.clickcount ;
                } else {
                    document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
                }

            }

I am successful in downloading the text file from the blob. But I want the notes to be saved on the website but could not find a correct solution to it. This is the code I have tried so far. I can just count the number of notes instead of getting the notes getting saved in the website itself. Please help.

Jerry
  • 1
  • I think you just skip some steps. Have you tried this solution? https://stackoverflow.com/questions/40385064/how-to-detect-download-complete-in-javascript – harmath Nov 25 '19 at 08:22
  • In this the user is selecting some existing file. But in my case the notes are being typed in a textbox and it is getting downloaded on clicking the save button. But I want the note to be present in the server itself instead of geting downloaded – Jerry Nov 25 '19 at 08:57

0 Answers0