[SOLVED] How to use script to create text file and download it

Lets say I wanted to have a project that downloads a text file, but it cant just be a pre made text file because some aspects of it are dictated by the downloader. Sort of like a “define the width and height of an svg then download it” type of thing. And by “sort of” I mean thats exactly what I am looking for.

Ok so looking through google I have found a solution for creating a text file then downloading it.

Simply set the File variable to a blob containing the file you want to download and it works

    function saveFile(url, filename) {
        const a = document.createElement("a");
        a.href = url;
        a.download = filename || "file-name";
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
    }
    const file = new Blob(["Hello, file!"], { type: "text/plain" });
    const url = window.URL.createObjectURL(file);
    saveFile(url, "myFile.txt");
    window.URL.revokeObjectURL(url);

Yes that does work, although I need to use quotation marks within the text file and that breaks the script.

there is a simple solution. just use \" to escape the quotation.

Yeah its working now.