Remove all CKEditor instances
Asked Answered
U

3

19

I have a form in which I have CKEditor replacing my <textarea>s (multiple). I want to remove all CKEditor instances from the page before submitting the form. How can I accomplish this?

I've looked at Remove CKEdit Instance but it didn't help me at all.

NOTE: All my CKEditors have a class "ckedit"

Untaught answered 27/7, 2012 at 12:19 Comment(3)
Short question, why would you need to do this?Heddle
It's been 3 years since I posted this, I no longer remember what I needed it for. There must have been a reason...Untaught
Yeah, I came across a solution like this, but have no idea why it's implemented, because it works fine without destroying it firstHeddle
J
59

This will destroy all CKEDITOR instances on a page:

for(name in CKEDITOR.instances)
{
    CKEDITOR.instances[name].destroy(true);
}
Jactitation answered 27/7, 2012 at 14:18 Comment(6)
for future people searching. This works great but when I tried to reload I was getting an error saying i.contentWindow was null. After googling I found by passing true to destroy that error will go awayXanthene
giving error: TypeError: a is null ....getDocumentElement().clearCustomData();a.clearCustomData();CKEDITOR.tools.remove...Sensualism
In case of errors try this: for(var a in CKEDITOR.instances){CKEDITOR.remove(CKEDITOR.instances[a]);}Nth
@Serban That's totally wrong. You're only removing it from the list of editor instances, but the whole object will remain in memory and you'll end up with a huge memory leak.Jactitation
@Jactitation unfortunately, nothing else seems to work for me. Your code gives the following error: Uncaught TypeError: Cannot read property 'clearCustomData' of null. When I try to destroy a single editor from the list of instances (using CKEDITOR.instances['inputProjectTarget8391'].destroy(); ) I get this: Uncaught TypeError: Cannot read property 'document' of undefined.Nth
But your code isn't really removing the editor, it's removing it only from a list, but it doesn't remove its elements from the page,the hooked events, etc... your code is only giving a false ilusion and in the long term you'll get some unexpected error that no one else can reproduce because you're ab-using the CKEditor APIJactitation
P
0

you can make use of .remove() of jquery, before submitting.

Portend answered 27/7, 2012 at 12:21 Comment(7)
But won't this remove the entire <textarea>? Since the textarea is holding the class 'ckedit'Untaught
those ckeditor instances, do they any Ids?? like a commin pattern of Ids? ck1, ck2..something like this;Portend
No unfortunately they do not. I already thought of looping though each element but I do not have time to rewrite that code at the moment. I only have a class 'ckedit' nothing else :(Untaught
okay these instance, do they have any value like null or something..if they have some value then you can loop through all you instances and get the value of every instance using this .val() method of jquer and if value is something then you can remove those instances???Portend
There is no repeating value nor attribute I can loop through. Is it possible to loop thought each element with jquery.each and use $(this) to remove the instance somehow?Untaught
yes it is possible but if you want to remove instances then you should have some condition inside each(). each() can interate through all specified elements...check this fiddle jsfiddle.net/EjbLx/6Portend
OK I've decided to use IDs, gonna rewrite everything, I tried CKEDITOR.instances.editor1.destroy(); and it works perfectly, does anyone know, can I use that function to somehow loop thought 50 ids and remove them if they exist. I don't wan't to write destory() function for 50 times -.-Untaught
A
-15

Have you tried just...

delete CKEDITOR;

I had a similar situation and this worked for me. Just make sure you re-create it the next time you need to use it. Otherwise try keeping an array of id's of all the instances you create and just loop through that array and destroy them all.

Autogenous answered 31/7, 2012 at 1:26 Comment(1)
Try deleting this answer please, make sure nobody uses this statementTamera

© 2022 - 2024 — McMap. All rights reserved.