Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting non-html text from CKeditor

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

like image 356
ozzy_mra Avatar asked Oct 15 '12 12:10

ozzy_mra


People also ask

How do I get CKEditor text?

Re: Get textvar editorData = CKEDITOR. instances. editor1. getData();

How do I set a value in CKEditor with JavaScript?

To set a value in CKEditor with JavaScript, we use the setData method. CKEDITOR. instances["fieldName"].

How do you hide and show CKEditor?

visibility = 'hidden';"+ ""+ "}" + "}" + "}"; This still works in hiding the DIV and in version 2.6 it would also appear to be hidden but in 3.0 the editor is still very much visible.


1 Answers

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();
like image 189
Reinmar Avatar answered Sep 29 '22 12:09

Reinmar