Generate and Save As Text File with Javascript

preview_player
Показать описание
How to let user save or download text file to their computer with javascript

Рекомендации по теме
Комментарии
Автор

Unfortunately pressing the "Save Text File" button does nothing. I've verified this in Firefox and Chrome.

rickhorvath
Автор

After a full year of searching, I finally found a way to do it!

Stevesteacher
Автор

Just one question:

the line var blob = new Blob(["test text"], {type: "text/plain;charset=utf-8"});

the object Blob is being defined on this same line? is this some json definition?

i´m just asking because i´m trying to take a generated code string and priting it inside the txt file.

I have :

function showCode() {
// Generate JavaScript code and display it.
= null;
var code =
alert(code);
}

this function is just for taking all the generated lua script on the page and save it on var code, however i was string to use saveAs directly to save the content of code:

saveAs(code, "script.lua");

Kerberos
Автор

How to save it into my directory not to download it?

igorkotljar
Автор

it doesn't work for me. i can't figure out why? i have javascript enabled on my browser. none of the sample scripts work when I try to run them ( i'm learning java ) I've never had this problem when learning any other programming language. i'm on kali linux and running chromium browser. but when I go to your site and run the script it works just fine...

Postulatedstate
Автор

Is there any way to automatically download the file, without any popup window the use has to click on?

CarloBianchi
Автор

Can you make a tutorial about how to read and show in screen the content of a txt file?

TheALTUVE
Автор

Hey Red Stapler, where can I find the tutorial video for saving image files?

nyamekorarane
Автор

Thank you, that's exactly what I was looking for. There aren't many examples on YouTube regarding these type of solutions, so I'm a bit disappointed to see this done with jQuery. I know how to read a bit of jQuery, so I should be able to rewrite this in vanilla JS.

ВасилисКарапас
Автор

how can i specify which folder to download the file to

athulantony
Автор

it doesn't save the name of the file or the type of the file it just saves as a file named download

russtycrussty
Автор

Doesn't work, even in your example... "saveAs not defined."

HasnainF
Автор

What’s the name of the sing in the background?

larrycornell
Автор

My vision isn't very good and I can't read your screen shots.

mastrake
Автор

Can you tell me how to add more text and writeline

anvan
Автор

Hi Red Stapler... How can you choose where the file downloads to please???

Baba-sofh
Автор

HOW CAN I DO THE JUMP OF LINE IN THE TXT FILE WITH THIS METHOD ???? I TRIED WITH \n and it doesnt work ...

cesarsantosvisballambis
Автор

Hey please say me whats the name of this music. I wanna download to put it on my project. :)

I already thank you

vitorgomespereira
Автор

How do I make the user write something on a box or prompt?

chrystiansilva
Автор

when i press the save button nothing happens, can you tell me why?

Thanks

georgianalexandru