简体   繁体   中英

word limit in Tiny MCE Editor

I have 4 Tiny MCE editor in my application on same page. I want to put max word limit to 100 (editor1 + editor 2 + editor 3 + editor 4 word count must be less than 100 words). whenever I should click on submit button the webpage should chaeck this validation ( or whenever the count increases more than 100 then the same page before clicking on submit button should alert the user)

I have gone through many online solution but not able to know how I can implement this functionality.

here is my code:

<script type="text/javascript" src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
 <script type="text/javascript" >


     tinyMCE.init({
         selector: 'textArea',  // change this value according to your HTML
         menu: {
             edit: { title: 'Edit', items: 'undo redo | cut copy paste pastetext | selectall' },
             insert: { title: 'Insert', items: 'link media | template hr' },
             format: { title: 'Format', items: 'bold italic superscript subscript' },
             tools: { title: 'Tools', items: 'spellchecker code' }
         },
         resize: 'both',
         plugins: "wordcount",
         encoding: "xml"            

     });
 var myVar = parseInt($('#content-word-count').text()); 
 if (myVar > 100){ "Your information exceeded than the max limit 100" };

</script>

<textarea id="editor1" rows="2" cols="20" runat="server" ></textarea> <br />
<textarea id="editor2" rows="2" cols="20" runat="server" ></textarea> <br />
<textarea id="editor3" rows="2" cols="20" runat="server" ></textarea> <br />
<textarea id="editor4" rows="2" cols="20" runat="server" ></textarea> <br />

<asp:Button ID="btnSave" runat="server" Text="Save"  OnClick="btnSave_Click" />

Please help me out.

You can ask any instance of TinyMCE for its current word count like this:

var editor1 = tinymce.get('editor1');
editor1.plugins.wordcount.getCount();

If you need to add the count from multiple editors you can expand this to get this information from each instance of TinyMCE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM