1

Is there a way to save CKEditor (text) data as a textfile local on a disk so one can open it later and proceed with editing ? Just like wordprocessors do ?

Ben
  • 677
  • 5
  • 19
  • Only when using server to write file. Javascript has no direct file access – charlietfl Mar 29 '15 at 12:13
  • @charlietfl: modern browsers have a built-in webserver. No need (other than fallback) to use a webserver to offer a download-link.. Probably a base64 data-url will also work as intermediate fallback for recent browsers. – GitaarLAB Apr 04 '15 at 23:38
  • @GitaarLAB _"modern browsers have a built-in webserver"_ Can describe details ?, links to documentations ? – guest271314 Apr 04 '15 at 23:45
  • 1
    @guest271314: Giving a good answer is a bit beyond the scope and space for a comment. Google `URL Store`. It is effectively a local/private mini webserver (including status-codes for XMLHttpRequest) serving any kind of binary or data, links are valid during session only. Also see: https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications#Using_object_URLs and http://stackoverflow.com/a/20537822/588079 – GitaarLAB Apr 04 '15 at 23:55
  • 1
    @GitaarLAB Perhaps interpreted "modern browsers have a built-in webserver" technically , literally, here:) see also http://help.opera.com/Windows/12.10/en/unite.html , http://stackoverflow.com/questions/5053244/is-it-possible-to-embed-a-http-server-in-a-google-chrome-extension , http://stackoverflow.com/questions/4240524/what-are-the-differences-between-opera-unite-and-node-js , http://serverfault.com/questions/212086/how-does-opera-unite-setup-a-web-server-without-port-forwarding – guest271314 Apr 05 '15 at 00:20
  • 1
    @guest271314: cool, didn't know that (all-tough a bit off-topic to the Q at hand). There is off-course a big difference here, the URL Store is not accessable outside the browser (as in, someone else even within the same network or computer can not access it (at least.. thats what I believe)). The links you shared are intended to turn the browser into a 'full' webserver that can be accessed by other users/browsers. – GitaarLAB Apr 05 '15 at 00:27
  • 1
    @GitaarLAB Yes ; initially , here , interpreted "modern browsers have a built-in webserver." _literally_ :) Cheers – guest271314 Apr 05 '15 at 00:30
  • 1
    @guest271314 Lol, the accompanying answer below would probably have cleared up what I was talking about, but it's week-end over here too `:)` – GitaarLAB Apr 05 '15 at 00:34

1 Answers1

0

Since the FileSaver interface is not going to survive, why not use the browser's built-in webserver?
(Even if you have hosting, why make that hosting-company rich by wasting data-transfer paid from your (boss') money.. Don't like 'greed', then think of the environment: traffic==electricity... Don't like the environment, then argue security: 'why ship the user's potentially private content over the net, twice')

Here is an example to get you started:

window.URL = window.URL || window.webkitURL;  //fallback for older prefixed objects

function update_download_lnk(str, elm){
  if(str){
    elm.href=window.URL.createObjectURL(  new Blob( [str], {type: 'text/plain'} )  );
    elm.style.display='';
  } else {
    elm.style.display='none';
  }
}
<textarea onchange="update_download_lnk(this.value, this.nextSibling);"
></textarea><a href="#" style="display:none">Download File (right-click save-as..)</a>

Some further reading here.

NOTE: smaller files can also be offered as base64 encoded dataURL.

GitaarLAB
  • 14,536
  • 11
  • 60
  • 80