I'm trying to create a ments tab for my website and insert an HTML form.
So far my form and ments tab is ready. I'd like to create a text document to store HTML form inputs.
I couldn't find a proper way to do that, like C++'s fstream
. I found some code with PHP, but I don't want to use PHP either.
Any way to do this?
I'm trying to create a ments tab for my website and insert an HTML form.
So far my form and ments tab is ready. I'd like to create a text document to store HTML form inputs.
I couldn't find a proper way to do that, like C++'s fstream
. I found some code with PHP, but I don't want to use PHP either.
Any way to do this?
Share Improve this question edited Dec 10, 2014 at 10:35 Sebastiano 12.3k6 gold badges49 silver badges80 bronze badges asked Dec 10, 2014 at 10:02 GetdachopaGetdachopa 151 gold badge1 silver badge7 bronze badges 1- 1 If you want to store data from an HTML form on a server you have to use some backend written in whatever language you would like to use. Most popular is surely PHP or maybe Python. If you want to use JavaScript you have to write an plugin for your Apache (if there isn't any), but I would be really concerned about the security than. – RodrigoDela Commented Dec 10, 2014 at 10:05
1 Answer
Reset to default 11You can use datauri and new download
property of anchor elements (<a>
) to achive it, without a server. Just randomly type something in the text box, click "export" and see what happens:
var container = document.querySelector('textarea');
var anchor = document.querySelector('a');
anchor.onclick = function() {
anchor.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(container.value);
anchor.download = 'export.txt';
};
<textarea></textarea>
<p><a href="#">Export</a></p>
You can achive other types of file download, just change text/plain
to the proper MIME type, and ensure that you encode the file content correctly. For example, <canvas>
is a good approach for generating images.