Is there any way by which I can count the characters entered in tinymce editor. I just want to set minimum character requirement. Or how to use tinyMCE.activeEditor.getContent()
properly for this purpose.
Asked
Active
Viewed 7,044 times
4

bɪˈɡɪnə
- 1,087
- 2
- 23
- 46
-
http://www.tinymce.com/wiki.php/TinyMCE3x:How_to_limit_number_of_characters/words – mplungjan Nov 11 '15 at 13:19
2 Answers
7
I believe that the better way to do this is using the getContent api:
// Get the HTML contents of the currently active editor
tinymce.activeEditor.getContent().length
// Get the raw text of the currently active editor
tinymce.activeEditor.getContent({format: 'text'}).length;
// Get content of a specific editor:
tinymce.get('content id').getContent().length
Please note the usage of the format
parameter in the second example in order to get the raw text instead of the parsed text with HTML tags.

roperzh
- 890
- 7
- 12
-
A perfect solution for those on version 4 where the wordcount plugin it's still limited to only words (and you don't have the option to upgrade of course). – elvin Sep 08 '20 at 19:51
0
Try this ->
var body = tinymce.get("txtTinyMCE").getBody();
var content = tinymce.trim(body.innerText || body.textContent);
return content.length;

ahervin
- 461
- 2
- 15