I use thickbox to open page editor with ckeditor inside. The main page contains js link to ckeditor and thickbox loads page with textarea and everything works fine. But if I open thickbox the second time without reloading main page I got error "uncaught exception: [CKEDITOR.editor] The instance "text" already exists." in firebug. It is predictable becouse textarea has the same name.
The way to fix it is to check if editor exists and to destroy it if it does. Is there any working way to do it?
I tried:
$(document).ready( function() { // I use jquery
if(typeof(CKEDITOR.instances.text)=="object")
{
CKEDITOR.instances.text.destroy();
}
CKEDITOR.replace("text");
});
but I got error in firebug: "Error: i.contentWindow is null
file: ckeditor.js
Line: 18"
and editor does not start, textarea is unchanged.
The way to fix it is to check if editor exists and to destroy it if it does. Is there any working way to do it?
I tried:
$(document).ready( function() { // I use jquery
if(typeof(CKEDITOR.instances.text)=="object")
{
CKEDITOR.instances.text.destroy();
}
CKEDITOR.replace("text");
});
but I got error in firebug: "Error: i.contentWindow is null
file: ckeditor.js
Line: 18"
and editor does not start, textarea is unchanged.
Re: New instance with the same name
this is what i use
and that seems to work...
you might also want to consider maybe adding a delay, or separating the 2 statements by some sort of logical step (such as closing and reopening a window)
more than likely what is happening is your destroy is not happening quick enough before you call it again... javascript is funny like that
try replacing that with
i know that makes no logical sense, but i bet you it works
Re: New instance with the same name
Re: New instance with the same name
CKEDTTOR.instances.text.destroy(true);
According to documentation if it is true it will not try to restore replacement.
It worked for me.
Tomas
Re: New instance with the same name
did you find a solution?
I have same kind of problem. I can remove and replace the instance with :
ckeditor.instances.myck.updateElement();
ckeditor.instances.myck.destroy();
ckeditor.replace('myck');
but when i try to submit the form. I have the "i.contenwindow is null" message
Thanks
Magicbob
Re: New instance with the same name
I've using Ajax submit to submit my form, but in the same submit script I remove the DOM elements to hide the form, that's give me the error with CKeditor.
So try to remove CKEditor Instances after submit and then remove the DOM elements with the form and it's childs.
Hope this helps you!
Re: New instance with the same name
I went tothe same conclusion
Frederic
Re:
Could you please provide the sample for the same.
I am getting error:
"Uncaught TypeError: Cannot read property 'document' of undefined"
When using destroy in my code.
My code:
var editroArray = ['editor1', 'editor2', 'editor3'];
for (var i = 0; i < editroArray.length; i++) {
var editor = CKEDITOR.instances[editroArray[i]];
if (editor) {
editor.destroy(true);
editor = null;
}
else
return;
}
Thanks,
Tech