dimanche 19 avril 2015

modify template file from web and save it to local using HTML5, JavaScript, jQuery

I'm trying to create a site, where some settings, set up by a client, may be written to a file, that is not located in the client's filesystem, but is a file of my project. Then this file, with some parts of it overwritten, must be saved to local storage.


For example:


template_file.txt contents:



My favourite color is WHITE.

I like GREEN tea with lemon.

Leaves on the trees are GREEN.



Web page initially has something like:

[Empty Text Field 1 Here]

[Empty Text Field 2 here]

[Empty Text Field 3 here]

Filename: [Empty Filename Field here]

{OK Button} {Save File Button}


(Text of template_file.txt is not visible to the client, but is included into the website's project.)


Client's input:

[red]

[black]

[Empty Text Field 3 here]

Filename: [generated_file]

{OK Button} {Save File Button}


(Field 3 left unchanged, {OK Button} clicked.)


generated_file.txt contents:



My favourite color is red.

I like black tea with lemon.

Leaves on the trees are GREEN.



({Save File Button} clicked. => Site proposes to save generated_file.txt to local filesystem.)


I have found a tutorial on how to save all the text from a textarea to file here:

Loading, Editing, and Saving a Text File in HTML5 Using Javascript


But I have no idea how to generate file, using partly overwritten template file from web for it. Any tips on how to do it (if it's actually possible) would be greatly appreciated.


Aucun commentaire:

Enregistrer un commentaire