Log in or register to post comments
Last post
jamesf's picture
Joined: 23/09/2009
Posts: 11
Getting CKEDITOR instance
Hello everyone,

Just downloaded CKEditor & CKFinder to see if it's suitable for our companies CMS. Really impressed so far but just running into a few problems.

How do you access the CKEditor instance? I've searched the forum and a few people have referenced this code but it doesn't seem to work for me:

for(var instanceName in CKEDITOR.instances) {
   console.log( CKEDITOR.instances[instanceName] );
}


I've only got one textarea on the page, but this is set dynamically so there could be more. I've tried accessing the instance using the following but none seem to work:

CKEDITOR.instances.editor1
CKEDITOR.instances[editor1]
CKEDITOR.instances["editor1"]


Any ideas?

Thanks for your help
maksokami's picture
Joined: 04/01/2010
Posts: 1
Re: Getting CKEDITOR instance
I use textarea id:

 <textarea name="html_link_content" id="content">TEXT</textarea>      
<script type="text/javascript">
      var editor = CKEDITOR.replace('html_link_content');

/*  =====INSTANCE====== */
var instance = CKEDITOR.instances.content;
instance.updateElement();
$("#output").attr("value",instance.getData());
</script>
tylerdurd's picture
Joined: 06/01/2010
Posts: 3
Re: Getting CKEDITOR instance
I use textarea id too, but isn't there a better solution ?
alfonsoml's picture
Joined: 31/12/2006
Posts: 3737
Re: Getting CKEDITOR instance
tylerdurd wrote:I use textarea id too, but isn't there a better solution ?

What kind of better solution?
tylerdurd's picture
Joined: 06/01/2010
Posts: 3
Re: Getting CKEDITOR instance
Sorry for my question,

i have found a solution by adding a class on my textarea and make my plugin's code more generic.

EDIT :
Nice, i have found a solution:
getParentEditor()
okoi's picture
Joined: 07/07/2010
Posts: 1
Re: Getting CKEDITOR instance
Hi, I thought I'd share how I get my instances...

CKEDITOR.instances is an object as declared in core/ckeditor.js line 22, so I run a foreach loop to determine it's methods and properties:

var myinstances = [];

//this is the foreach loop
for(var i in CKEDITOR.instances) {

   /* this  returns each instance as object try it with alert(CKEDITOR.instances[i]) */
    CKEDITOR.instances[i]; 
   
    /* this returns the names of the textareas/id of the instances. */
    CKEDITOR.instances[i].name;

    /* returns the initial value of the textarea */
    CKEDITOR.instances[i].value;  
 
   /* this updates the value of the textarea from the CK instances.. */
   CKEDITOR.instances[i].updateElement();

   /* this retrieve the data of each instances and store it into an associative array with
       the names of the textareas as keys... */
   myinstances[CKEDITOR.instances[i].name] = CKEDITOR.instances[i].getData(); 

}


Hope this helps... Pardon my bad english...