How to properly destroy CKEditor instance? How to properly destroy CKEditor instance? javascript javascript

How to properly destroy CKEditor instance?


I had this problem. What a pain.

To properly destroy the editor instance, try

if (CKEDITOR.instances.myInstanceName) CKEDITOR.instances.myInstanceName.destroy();

From the documentation here

I solved the missing content issue by assigning the contents of the editor to a hidden field prior to postback. I'm using ASP.Net, but it should work universally.

in the client-side click handler of the submit button, call

if (CKEDITOR.instances.myInstanceName)    document.getElementById('hiddenField').value = CKEDITOR.instances.getData();


I once used angularjs ui-router with one CKEDITOR instance for each sub-view. I used the following solution to clear the instances every time I load the ui-view

for(name in CKEDITOR.instances){    CKEDITOR.instances[name].destroy()}


In my situation

CKEDITOR.instances.myInstanceName.destroy();

didn't help, because I'd opened CKEditor in jquery dialog on double click on some item. When I closed editor and then opened them again, my code crashed.
Solution was using

CKEDITOR.instances.myInstanceName.destroy(false);

which updated DOM element (link to documentation).