Getting non-html text from CKeditor

ozzy_mra picture ozzy_mra · Oct 15, 2012 · Viewed 29.1k times · Source

In my application, in insert news section, i use a sub string of news content for news Summary. for getting news content text from users,i use CKEditor and for news summary i use substring method to get a certain length of news content.but when i'm working with CKEditor i get text with html tags and not plain text and when i use substring method, my news summary become messed! how do i get raw text from this control? i read this but i can't use getText() method

Answer

Reinmar picture Reinmar · Oct 15, 2012

Try code like this:

CKEDITOR.instances.editor1.document.getBody().getText();

It works fine for me. You can test it on http://ckeditor.com/demo. It's not ideal (text in table cells is joined together without spaces), but may be enough for your needs.


EDIT (20 Dec 2017): The CKEditor 4 demo was moved to https://ckeditor.com/ckeditor-4/ and uses different editor names, so the new code to execute is:

CKEDITOR.instances.ckdemo.document.getBody().getText();

It's also important that it will work in the "Article editor" and in the "Inline editor" you need to get text of a different element:

CKEDITOR.instances.editor1.editable().getText();