最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Word count in CKEditor 4 - Stack Overflow

programmeradmin1浏览0评论

I'm using the Word count Plugin on CKEditor 4, but it exceeds the character count every time.

Here is my config:

config.wordcount = {

// Whether or not you want to show the Char Count
showCharCount: true,

// Option to limit the characters in the Editor, for example 200 in this case.
charLimit: 200
};

What am I doing wrong?

I'm using the Word count Plugin on CKEditor 4, but it exceeds the character count every time.

Here is my config:

config.wordcount = {

// Whether or not you want to show the Char Count
showCharCount: true,

// Option to limit the characters in the Editor, for example 200 in this case.
charLimit: 200
};

What am I doing wrong?

Share Improve this question edited Nov 17, 2016 at 16:29 GʀᴜᴍᴘʏCᴀᴛ 9,02920 gold badges90 silver badges160 bronze badges asked May 30, 2014 at 14:56 Hari SankarHari Sankar 661 gold badge1 silver badge5 bronze badges 6
  • Give an example of text that "exceeds" the word count – Lee Taylor Commented May 30, 2014 at 15:00
  • "Sometimes" is not the most precise description of the problem. And if this happens sometimes, then maybe you should report a bug to the plugin author? – Reinmar Commented May 30, 2014 at 15:01
  • @LeeTaylor I set the char limit to 10 and just typed "xdfxcfgcdcggvg" – Hari Sankar Commented May 30, 2014 at 15:04
  • 1 @HariSankar - Please edit your question and add that info. Also, change sometimes to every time, if that's what you mean. – Lee Taylor Commented May 30, 2014 at 15:08
  • 1 Basically, I need to restrict users to enter not more than 2000 chars. – Hari Sankar Commented May 30, 2014 at 15:13
 |  Show 1 more ment

3 Answers 3

Reset to default 3

The WordCount plugin only counts words - it doesn't prevent you from entering text.

I wrote a similar plugin a while ago (http://ckeditor./ment/128388#ment-128388) which counted words or characters and allowed you to enter a "warning" limit which got displayed at the bottom.

The difficultly of limiting to a specific number of characters in CKE is that markup counts as content. It's a doddle to do with a regular textarea, but once you start using having bold and anchor tags involved it's much more plicated - does your character limit include or exclude markup? If it includes then how do you want to handle closing tags? If you want to limit to words then it's a little easier, but still not a walk in the park. Of course then you have to factor in pasting too ;)

Personally if I were tackling this, I'd hook into the counter so that if you exceed the count (this excludes all markup) you disable the ability to save.

You need a ma after charLimit: 200:

charLimit: 200,

you also need:

config.extraPlugins = "wordcount,notification";

You need to set maxCharCount: 200, hardlimit: true

maxCharCount: 200,
hardlimit: true,

Please find below the config

config.extraPlugins = 'wordcount';

    config.wordcount = {
            
            showCharCount: true,
            
            maxCharCount: 200,

            hardLimit: true,

    };

for more details refer to Word Count Plugin

发布评论

评论列表(0)

  1. 暂无评论