1

I have been working on an on/offline text-editing HTML page to take notes. It has a <textarea/> like the ask page.

The problem is if the browser crashes, then some work may be irrecoverable. What is a simple, clean way to save the real-time contents of the HTML page to a .html file? In Chrome or IE is there any way to save the HTML document as it is exactly displayed?

I tried a File...Save As in Chrome and IE will not persist the text changes I made.

The question https://stackoverflow.com/questions/21486908/save-a-webpage-after-its-variables-have-been-changed looks similar, but is lengthy, and nobody answered it (yet).

Community
  • 1
  • 1
Identity
  • 113
  • 3

1 Answers1

1

The HTML/JS context in a browser runs in sandboxed mode, meaning that you can't read or write files programatically in JS directly to your filesystem. Take a look at web storage to check a way to do it indirectly (using browser abstractions). It's one of the most common ways of implementing persistence in an offline web application.

You'll probably find browser-specific functions that can make this, but I don't know of any portable solution for this that doesn't rely on plugins.

There's a similar question, but I think you'll run in the same problem that you can't save the changes in the HTML structure and content

Community
  • 1
  • 1
Allan
  • 525
  • 2
  • 7
  • I don't know of web storage yet. W3C articles seem wordy to me, but you [second suggestion](http://stackoverflow.com/a/19502129/3266609) looks more approachable. – Identity Feb 15 '14 at 15:26
  • The W3C page contains the specification, it's kind of a heavy read :) Try [this tutorial](http://coding.smashingmagazine.com/2010/10/11/local-storage-and-how-to-use-it/). Note that the second suggestion will probably only trigger the save dialog, so it won't be much different from what you have now (I haven't tested it though). – Allan Feb 15 '14 at 15:29