Tuesday, June 4, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  150] [ 6]  / answers: 1 / hits: 20014  / 15 Years ago, tue, march 30, 2010, 12:00:00

I've added a CKEditor instance programmatically to my page in the code-behind of my ASP.NET page:



VB.NET:



itemEditor = New CkEditor
cell.Controls.Add(itemEditor)


... which works fine. I can get the HTML on the postback and do stuff with it.



However, I also want to do some client-side stuff with it, specifically take a selected item out of another control, and insert it into the text by handling the onchange event.



So, how can I get the name of the editor instance in the JavaScript, so that I can do stuff like:



function GetCkText()
{
var htmlFromEditor = CKEDITOR.instances['editorName'].getData();
// do stuff with htmlFromEditor
}

More From » ckeditor

 Answers
16

Assuming you only have one editor instance:



for ( var i in CKEDITOR.instances ){
var currentInstance = i;
break;
}
var oEditor = CKEDITOR.instances[currentInstance];


Here is what the JavaScript API says about instances.



Here is another way of defining the CKEditor. Here 'fck' is the input fields id:



CKEDITOR.replace( 'fck', {
customConfig : prefix + 'js/ckeditor/config.js',
height: 600,
width: 950
});

editor = CKEDITOR.instances.fck;


Notice how I am then able to reference the instance using .fck.


[#97210] Friday, March 26, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stacyl

Total Points: 131
Total Questions: 105
Total Answers: 94

Location: Egypt
Member since Tue, May 3, 2022
2 Years ago
stacyl questions
Thu, Jan 28, 21, 00:00, 3 Years ago
Sun, Mar 8, 20, 00:00, 4 Years ago
Tue, Feb 25, 20, 00:00, 4 Years ago
Tue, Feb 11, 20, 00:00, 4 Years ago
;