0

I would like to save/export my URL address to the text file (.txt).

Firstly I've managed with copying my URL address to the <textarea> by following this query:

How to copy URL on button click?

It works perfectly for me, although I need a bit more here. I need to have it exported to the text file. Because I work on a local server, I use the get method in my form. It results in quite a long URL, which can be retrieved (reopened) when copied. I think it could be convenient for me to have it stored somewhere, like in the .txt file.

I used this solution:

https://www.websparrow.org/web/how-to-create-and-save-text-file-in-javascript

for saving dynamic data, although it doesn't work for me.

My code looks like this now:

        <script>
            function Copy() {
        var Url = document.getElementById("url");
        Url.innerHTML = window.location.href;
        console.log(Url.innerHTML)
        Url.select();
        document.execCommand("copy");
        }  

        function saveStaticDataToFie() {
            var Urltext = document.getElementById("url").value;

            var blob = new Blob([Urltext], {type: "text/plain;charset=utf-8"})
            saveAs(blob, "survey.txt");
        }
       </script>

       <button type="button" onclick="saveStaticDataToFile();">Click to Save</button>

I see no reaction at all. What have I done wrong here?

Geographos
  • 827
  • 2
  • 23
  • 57

0 Answers0