1

I need to create a single html where the person can input text in text fields, then click a button and save the file itself, so he wont lose changes. The idea is similiar to what wysiwyg does to html documents, but I need that to be implemented on the doc itself.

Where do I start from? I can't find anything like that on Google, perhaps I'm searching the wrong therms.

Need something that uses HTML + Javascript, no server side scripting.

  • Yes, you can, but it is not easy. Take a look at the [FileSystem API](http://caniuse.com/#feat=filesystem) and everything else that [TiddlyWiki](http://tiddlywiki.com/) does to support legacy browsers. – Sean Vieira Feb 25 '14 at 18:22
  • 1
    if this need work only for you, HTA can write files, including the one at location.href. i've made one that split the html by – dandavis Feb 25 '14 at 18:39

2 Answers2

2

JavaScript alone does not have the ability to modify files on your file system. All browsers do this for (good) security reasons. You will not be able to make changes to the html document itself (but according to the comment by Sean below, you might be able to produce a new copy of the document).

You might try using cookies to store the input values (automatically write them and load them when the document opens). There are various jQuery plugins available to aide in reading and writing cookies.

In business or enterprise systems this is usually done with a database, which would require server-side scripting.

Cᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194
  • Actually, it is quite possible - see [TiddlyWiki](http://tiddlywiki.com/) and the [FileSystem API](http://caniuse.com/#feat=filesystem) – Sean Vieira Feb 25 '14 at 18:18
  • @SeanVieira: Fair enough; I slightly modified by answer. – Cᴏʀʏ Feb 25 '14 at 18:24
  • Related: http://stackoverflow.com/questions/3665115/create-a-file-in-memory-for-user-to-download-not-through-server – Cᴏʀʏ Feb 25 '14 at 18:28
  • Thanks - just FYI, a TiddlyWiki actually is a self-modifying file - it can (in some environments) overwrite itself on the file system with the changes you make to it. (The details of *how* it does that are various bits of arcane black magic best left to those who want to peer into the depths of [`core/savers`](https://github.com/Jermolene/TiddlyWiki5/tree/master/core/modules/savers)) – Sean Vieira Feb 25 '14 at 18:41
1

I think most of these answers are incorrect. Using the FileSystem API, content is only saved to a sandboxed hidden folder, the user has no control as to where it is saved.

As suggested by Sean Vieira, using TiddlyWiki is a good solution.

However, if you want to customise it, you can make a Flash/JS bridge in which the Flash SWF saves the actual content.

Riftes
  • 36
  • 3
  • I think most answers are like 50% correct, in one hand they are right cause that's what they know about the subject, in the other hand they are not considering the fact that might actually be a solution for this problem, as Sean Vieira suggested about TidlyWiki. –  Feb 25 '14 at 19:47
  • Been taking a look, it seems to be very difficult, I think I'll just use WYSIWYG –  Feb 25 '14 at 19:50