Get Plain Text from FCKEditor in any Browser.

The Following Function will help to get plain text from the FCKEditor in almost any browser.

// below is the protyping for trim string.
function trimString (str) {
str = this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

String.prototype.trim = trimString;

//following function will return plain text
function GetPlainText(FCKEditorID) {
var FEditor = FCKeditorAPI.GetInstance(FCKEditorID);
var Result = "";
if (FEditor.EditorDocument.body.textContent || FEditor.EditorDocument.body.textContent=="" ) {
//Firefox compitable browser
Result = FEditor.EditorDocument.body.textContent.trim();
}
else {
//IE compitable browser
Result = FEditor.EditorDocument.body.innerText.trim();
}
return Result;
}

Comments

Anonymous said…
Great article.. Solved my problem
Omar Abdallah said…
Thanks alot, you saved me alot of time.
Anonymous said…
Use this :

var FEditor = FCKeditorAPI.GetInstance("fckid");
var editorContent = FEditor.EditingArea.Document.body.innerHTML; // HtmlEncoded
Anonymous said…
CKEditor 3 with jQuery :

$.trim($('.jquery_ckeditor').ckeditorGet().document.getBody().getText())

Popular posts from this blog

To Move items from one ListBox to another Listbox

Receive Json Web response in C#