CKEditor – auto save

A follow on from the previous post CKEditor custom dialog you can auto save the content with sending a AJAX call to another page that will save the content and also give back a updated time of that content saved.

I created a function called autosave(), that will call itself every 20 seconds (20000 milliseconds). This will get the data (getData()) from the CKEditor instance called content and then go some JQuery to do the actual AJAX function which in-turn calls the url autosave.php (can be any backend page that will deal with saving the data) and once the backend page has completed then update the HTML element with the ID of lastsavetime to the new time that is returned from the webpage.

function autosave()
   var t = setTimeout("autosave()", 20000);
  var content = escape(CKEDITOR.instances.content.getData());
   if (content.length > 0)
           type: "POST",
           url: "autosave.php?method=saveCKEditor",
           data : "content="+content,
           cache: false,
           success: function(message)
               $("#lastsavetime").empty().append("Last saved : "+message);
}); ";

3 thoughts on “CKEditor – auto save”

Leave a Reply

Your email address will not be published. Required fields are marked *